java写applet的简单介绍
今天给各位分享java写applet的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
javaAppleT
Applet可以翻译为小应用程序,Java Applet就是用Java语言编写的这样的一些小应用程序,它们可以直接嵌入到网页中,并能够产生特殊的效果。包含Applet的网页被称为Java-powered页,可以称其为Java支持的网页。
当用户访问这样的网页时, Applet被下载到用户的计算机上执行,但前提是用户使用的是支持Java的网络l浏览器。由于Applet是在用户的计算机上执行的,因此它的执行速度不受网络带宽或者Modem存取速度的限制。用户可以更好地欣赏网页上Applet产生的多媒体效果。
在Java Applet中,可以实现图形绘制,字体和颜色控制,动画和声音的插入,人机交互及网络交流等功能。 Applet还提供了名为抽象窗口工具箱(Abstract Window Toolkit, AWT)的窗口环境开发工具。 AWT利用用户计算机的GUI元素,可以建立标准的图形用户界面,如窗口、按钮、滚动条等等。目前,在网络上有非常多的Applet范例来生动地展现这些功能,读者可以去调阅相应的网页以观看它们的效果。
Applet的工作原理.
含有Applet的网页的HTML文件代码中部带有applet 和/applet这样一对标记,当支持Java的网络浏览器遇到这对标记时,就将下载相应的小应用程序代码并在本地计算机上执行该Applet。
例子
带有一个Applet的主页
上面这个例子就是一个简单主页的HTML文件代码。代码第五行中的p,是为了确保Applet出现在新的一行,若没有它, Applet将会紧接着上一行的最后一个单词出现。代码第六、七两行是关于Applet的一些参数。其中第六行是必需的Applet参数,定义了编译后的包含Applet字节码的文件名,后缀通常为".class";和以像素为单位的Applet的初始宽度与高度。第七行则是附加的Applet参数,它由一个分离的标
在Java中编写Applet
import java.awt.*;
import java.applet.*;
public class Q4 extends Applet
{
TextField text=new TextField();
int number;
String str;
public void init()
{
add(text);
number=(int)(10*Math.random());
text.setText(""+number);
text.setEditable(false);
}
public void paint(Graphics g)
{
str="the number is"+number;
g.drawString(str,50,50);
}
}
/*
applet code="Q4.class" width="300" height="100"
/applet
*/
java编写一个Applet程序
public class MyApplet extends Applet implements ActionListener{
private JLabel yourChoiceLabel;
@Override
public void init() {
super.init();
setLayout(new BorderLayout());
setSize(379, 273);
final JPanel panel = new JPanel();
panel.setLayout(null);
add(panel, "Center");
final ButtonGroup buttonGroup = new ButtonGroup();
final JRadioButton maleRadioButton = new JRadioButton();
buttonGroup.add(maleRadioButton);
maleRadioButton.setText("Male");
maleRadioButton.setBounds(102, 60, 129, 24);
maleRadioButton.addActionListener(this);
panel.add(maleRadioButton);
final JRadioButton femaleRadioButton = new JRadioButton();
buttonGroup.add(femaleRadioButton);
femaleRadioButton.setText("Female");
femaleRadioButton.setBounds(102, 90, 129, 24);
femaleRadioButton.addActionListener(this);
panel.add(femaleRadioButton);
yourChoiceLabel = new JLabel();
yourChoiceLabel.setBounds(87, 120, 188, 34);
panel.add(yourChoiceLabel);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() instanceof JRadioButton){
JRadioButton radio = (JRadioButton)e.getSource();
yourChoiceLabel.setText("Your Choice: " + radio.getText());
}
}
}
编写一个Java的小程序Applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Try extends Applet implements ActionListener
{
public void init()
{
Button b=new Button("请按按钮");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
Frame f=new Frame("警告");
f.setSize(200,100);
f.setLocation(300,300);
f.add(new Label("你按了按钮!"));
f.setVisible(true);
}
}
java编写applet程序
随意写了下,不是很好,楼主可参考下
=======================================
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends JApplet {
/** Creates a new instance of MyApplet */
public MyApplet() {
}
public void init(){
myFont = new Font("Dialog",Font.BOLD,16);
Bigger = new JButton("BIGGER");
Smaller = new JButton("Smaller");
jPanel1 = new JPanel();
jPanel2 = new JPanel();
jLabel1 = new JLabel("This is a test!!");
jLabel1.setFont(myFont);
jPanel1.setLayout(new FlowLayout());
jPanel1.add(Bigger);
jPanel1.add(Smaller);
jPanel2.add(jLabel1);
Container cp= this.getContentPane();
cp.setLayout(new BorderLayout());
cp.add(jPanel1,BorderLayout.SOUTH);
cp.add(jPanel2,BorderLayout.CENTER);
Bigger.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
BiggerActionPerformed(evt);
}
});
Smaller.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
SmallerActionPerformed(evt);
}
});
this.setVisible(true);
}
private void BiggerActionPerformed(ActionEvent evt){
int size = myFont.getSize()+2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}
private void SmallerActionPerformed(ActionEvent evt){
int size = myFont.getSize()-2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}
private JButton Bigger,Smaller;
private JPanel jPanel1,jPanel2;
private JLabel jLabel1;
private Font myFont;
}
关于java写applet和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-08,除非注明,否则均为
原创文章,转载请注明出处。