event handling in Java

来源:互联网 发布:问卷调查自动填写软件 编辑:程序博客网 时间:2024/04/29 15:45
import javax.swing.*;import java.awt.event.*;public class SimpleGui implements ActionListener {    JButton button;        public static void main(String[] args) {        SimpleGui gui = new SimpleGui();        gui.go();    }        public void go() {        JFrame frame = new JFrame();        button = new JButton("click me");                button.addActionListener(this);                frame.getContentPane().add(button);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(300, 300);        frame.setVisible(true);    }    @Override    public void actionPerformed(ActionEvent event) {        // TODO Auto-generated method stub        button.setText("I've been clicked!");    }    }


0 0
原创粉丝点击