Yes. As a program runs, it might add or remove components and change the size of the frame to fit them.
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".
What do you suppose this line from the program does?
JFrame frame = new JFrame("Test Frame 1");