事件监听
package java;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test1{
JFrame jf;
JButton jb;
JPanel jp;
public test1(){
jf = new JFrame("小小监听器");
jb = new JButton();
jb.addActionListener((ActionListener) this);
jp = new JPanel();
jf.add(jp);
jp.add(jb);
jf.setSize(200,150);
jf.setVisible(true);
}
public class event extends JFrame {
private JButton jb= new JButton("我是按钮,单机我");
public event(){
jb.addActionListener(new jbAction());
}
class jbAction implements ActionListener{
public void actionPerformed(ActionEvent arg[]) {
jb.setText("我被单击了");
}
public void main(String args[]){
new test1();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
}}}}