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(){
        
    }
}

 

posted on 2016-01-08 18:38  13rj1115  阅读(526)  评论(0编辑  收藏  举报

导航