开发者

JButton is a quitButton

开发者 https://www.devze.com 2022-12-09 03:20 出处:网络
I have a coded a program GUI phone book.It has textfields such as name, address, city,..etc.I also have three buttons.Add开发者_StackOverflow中文版, clear, quit.My program is serializable using a thre

I have a coded a program GUI phone book. It has textfields such as name, address, city,..etc. I also have three buttons. Add开发者_StackOverflow中文版, clear, quit. My program is serializable using a thread to write to my disk file every 2 sec. a new address. How do I code the quit button to quit running and writing to the disk?


quitButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
        serializeMe();
        System.exit(0);
    }
});

This is a very short version. You should probably make proper use of stuff like Actions, i.e.

Action quitAction = new AbstractAction() {
    public void actionPerformed(ActionEvent actionEvent) {
        serializeMe();
        System.exit(0);
    }
};
quitButton = new JButton(quitAction);
0

精彩评论

暂无评论...
验证码 换一张
取 消