import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class guiTest extends Applet implements ActionListener {//Button button1, button2;
TextField buttonshow= new TextField(14);
// Label textlabel;public void inti(){
setLayout(new FlowLayout(FlowLayout.LEFT));Panel panel1 = new Panel();
Panel panel2 = new Panel();panel1.setLayout(new FlowLayout(FlowLayout.LEFT));
panel2.setLayout(new FlowLayout(FlowLayout.LEFT));Button button1 = new Button ("button1");
Button button2 = new Button ("button2");Label textlabel = new Label ("Text Label");panel1.add(textlabel);
panel1.add(buttonshow);panel2.add(button1);
panel2.add(button2);add(panel1);
add(panel2);button1.addActionListener(this);
button2.addActionListener(this);
}public void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();
if (cmd.equals("button1")) {
buttonshow.setText("button1 was pressed");
buttonshow.setBackground (Color.red);
}
else if (cmd.equals("button2")){
buttonshow.setText("button2 was pressed");
buttonshow.setBackground (Color.white);
}
}}
在elipse没有错,可是运行就是一片空白?为什么啊?是不是在一个project里只能有一个applet? 另一个applet程序运行正常。