Parents : Curriculum : ICT
6th Form ICT
Making the GUI interactive
The GUI that you currently have does not respond to user input. Neither of the buttons work, and when you
cliuse the GUI you find that in the command prompt window the program is still running. This is the first
problem we will solve, which is telling the JVM (Java Virtual Machine) that the program is no longer required.
To do this you need to add this code into the program:
//Create and set up the window.
JFrame frame = new JFrame("6th Form Tester");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
This code operates on the Frame that has been created. The EXIT_ON_CLOSE operation, not surprisingly,
makes the program exit when the user closes the frame. This behaviour is appropriate for this program because
the program has only one frame, and closing the frame makes the program useless.
Recompile the code using the command
C:/> javac SwingApplication.java
Run the program with the command
C:/> java SwingApplication
If this is successful you should see that the command window cursor blinks next to the command prompt
(C:/>). Then you can move onto making the buttons work.
|