JButton is a quitButton
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);
精彩评论