您的位置:首页 > 编程语言 > Java开发

event handling in Java

2015-07-28 09:03 281 查看
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!");
}

}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: