Running the GUI Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Yes. As a program runs, it might add or remove components and change the size of the frame to fit them.

Running the GUI Program

The program is an application, so it has a main() method where it starts running. Even though it does not do much, run this program and play with it. To run the program, first copy-paste-save the program to a file called TestFrame1.java. Then, compile it and run it as usual:

C:/> javac TestFrame1.java
C:/> java  TestFrame1
         
     program runs and displays the frame

The program displays an empty frame. While the program is running, you can click on the frame and drag it around, you can minimize it, you can grab a border and resize it, and so on. All of this is built into the JFrame class. Your program gets all of these features when it constructs a JFrame object.

The frame remains "alive", even though there is nothing explicit in the program to keep it running. To stop the program, click on the "close button".

QUESTION 4:

What do you suppose this line from the program does?

JFrame frame = new JFrame("Test Frame 1");