事件4:点击一个按钮,改变按钮上面的字

来源:互联网 发布:淘宝打折软件 编辑:程序博客网 时间:2024/05/17 04:55
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class actionTest extends JFrame implements ActionListener{
    
public static void main(String s[]){
        
new actionTest();
    }

    
public actionTest(){
        JButton b
=new JButton("ok");
        b.addActionListener(
this);
        
this.getContentPane().add(b);
        
this.setSize(200,200);
        
this.setVisible(true);
    }

    
public void actionPerformed(ActionEvent e){
        JButton jb
=(JButton)e.getSource();
        
if(e.getActionCommand().equals("ok"))
            jb.setText(
"Clicked");
        
else
            jb.setText(
"ok");
    }

}
 
原创粉丝点击