I have a coded a program GUI phone book. It has textfields such as name, address, city,..etc. I also have three buttons. Add, 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?
+1
A:
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);
Bombe
2009-10-24 20:33:16
Thank you. When I added the serializeMe() my IDE generated a method for me to support. How do I support this method?
EbonyJava
2009-10-24 20:51:04
In the serializeMe() method you can just call the same logic that your thread is normally calling every 2min. You just want to serialize the same data to make sure it is up to date on quit correct?
broschb
2009-10-24 23:05:53