标签:
获取事件监听需要获取实现ActionListener接口的方法,
public class SimpleEvent extends JFrame{
private JButton jb=new JButton("我是按钮,点击我");
public SimpleEvent(){
setLayout(null);
setVisible(true);
setSize(200, 100);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c=getContentPane();
c.add(jb);
jb.setBounds(10, 10, 300, 30);
jb.addActionListener(new jbAction());
}
class jbAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
jb.setText("我被点击了");
}
}
public static void main(String[] args) {
new SimpleEvent();
}
}
标签:
原文地址:http://www.cnblogs.com/douyunqian3520/p/5521629.html