JButton的监听
import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Hello extends Applet{ JButton bt=new JButton("OK"); Label lb=new Label("Hello"); public void init(){ this.add(lb); this.add(bt); } public void start(){ bt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { if(lb.getText().toString().equals("Hello")) { lb.setText("你好"); bt.setText("确定"); } else{ lb.setText("Hello"); bt.setText("OK"); } } }); } public void stop(){ } public void destroy(){ } }