我试了下,没有什么问题,代码如下.每按一下button,label上的数字就加1
import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class Applet1 extends Applet {
boolean isStandalone = false;
Label label1 = new Label();
Button button1 = new Button();
int Count=0; //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() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
label1.setText("label1");
button1.setLabel("button1");
button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
this.add(label1, null);
this.add(button1, null);
} //Get Applet information
public String getAppletInfo() {
return "Applet Information";
} //Get parameter info
public String[][] getParameterInfo() {
return null;
} void button1_actionPerformed(ActionEvent e) {
Count++;
label1.setText(String.valueOf(Count));
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class Applet1 extends Applet {
boolean isStandalone = false;
Label label1 = new Label();
Button button1 = new Button();
int Count=0; //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() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
label1.setText("label1");
button1.setLabel("button1");
button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
this.add(label1, null);
this.add(button1, null);
} //Get Applet information
public String getAppletInfo() {
return "Applet Information";
} //Get parameter info
public String[][] getParameterInfo() {
return null;
} void button1_actionPerformed(ActionEvent e) {
Count++;
label1.setText(String.valueOf(Count));
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货