I made a GUI file I/O application program using java.awt.Frame. There are two buttons labelled "ENTER" and "DONE". The enter button makes the program store the data from the Textfield to the file while the done button causes the program to exit. The event of clicking the "ENTER" button is handled by the action() method while that of the "DONE" button is handled by the handleEvent() method. The program runs and does the job perfectly but the problem is whenever I click on a button, the terminal window appears behind the GUI Frame that displays a long runtime exception message. I identified one of the lines among the several in the entire exception message as pointing on a line in the handleEvent() method (line:78).
See the full exception message here. (Google Docs)
Below is the definition of both the handleEvent() and action() methods. Please predict the possible causes of the runtime exception and help me solve it. Thanks.
64 public boolean action(Event event, Object o){
65 if(event.target instanceof Button){
66 if(event.arg.equals("ENTER")){
67 try{
68 addRecord(); //calls the function to write data to the file
69 }
70 catch(Exception e){}
71 }
72 }
73 return super.action(event,o);
74 }
...
...
76 public boolean handleEvent(Event e){
77 if(e.target instanceof Button){
78 if(e.arg.equals("DONE"))
79 System.exit(0); //exits the program
80 }
81 return super.handleEvent(e);
82 }
...
...
84 public static void main(String args[]){
85 new ClassName().prepareGUI(); //prepareGUI() setups the Frame
86 }