问答题
注意:不改动程序的结构,不得增行或删行。
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
public class ex2_3 extends Applet implements ActionListener {
private String str="ok";
private Label l;
private Button btn;
public void init() {
setLayout(null);
l=new Label(str);
l.reshape(10, 10, 100, 30);
add(l);
btn = new Button("First");
btn.reshape(10, 50, 60, 20);
l.addActionListener(this);add(btn);
btn = new Button("Second");
btn.reshape(10, 100, 60, 20);
btn.setActionCommand("First");
btn.addActionListener(this);
add(btn);
}
public void actionPerformed(ActionEvent ae) {
str="Command: " +ae.getActionCommand();
btn.setText(str);}
}
ex2_3.html