📄 applet1.java~5~
字号:
package exp3;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Panel;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Applet1 extends Applet {
Image imgSeq[];
int numImg=10;
String fname="T";
int i=0;
private boolean isStandalone = false;
Button button1 = new Button();
Panel panel1 = new Panel();
GridLayout gridLayout1 = new GridLayout();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
imgSeq=new Image[numImg];
for (int j=1;j<=numImg;j++)
imgSeq[j-1]=getImage(getCodeBase(),fname+j+".gif");
Panel p1=new Panel();
p1.setBackground(Color.yellow);
p1.add(new Button("button in panel1"));
p1.add(new TextField("in panel1"));
add(p1);
Panel p2=new Panel();
p2.setBackground(Color.green);
p2.add(new Button("button in panel2"));
p2.add(new TextField("in panel2"));
add(p2);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
button1.setLabel("button1");
button1.addActionListener(new Applet1_button1_actionAdapter(this));
this.setBackground(SystemColor.control);
panel1.setForeground(Color.orange);
panel1.setLayout(gridLayout1);
this.add(button1, null);
this.add(panel1, null);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void button1_actionPerformed(Graphics e) {
e.drawImage(imgSeq[i],50,50,this);
i=i+1;
if(i==10)
i=0;
for(int j=0;j<2000000;j++)
j=j;
repaint();
}
}
class Applet1_button1_actionAdapter implements java.awt.event.ActionListener {
Applet1 adaptee;
Applet1_button1_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -