Answer:
It creates an object of the class JFrame
and gives the frame a title.
The Program Explained
When you create a JFrame object it is not automatically displayed.
A large application might create several JFrame objects, but might only
display one of them at a time.
Here is the program again:
import java.awt.*; // 1. import the application windowing toolkit import javax.swing.*; // 2. import the Swing classes. Note the "x" in javax. public class TestFrame1 { // usual main() method public static void main ( String[] args ) { JFrame frame // 4. a reference to the object = new JFrame("Test Frame 1"); // 3. construct a JFrame object frame.setSize(200,100); // 5. set it to 200 pixels wide by 100 high frame.setVisible( true ); // 6. ask it to become visible on the screen frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); // 7. say what the close button does } }
Here is an explanation of the program:
- The AWT is imported since it defines many classes that GUIs use.
- For most programs you must do this.
- The Swing package is imported since that is where JFrame is defined.
- Notice the 'x' in javax.
- A
JFrameobject is constructed. - The reference variable
framerefers to theJFrameobject. - The frame's
setSize()method sets its size. - The frame's
setVisible()method makes it appear on the screen. - The frame's
setDefaultCloseOperation()sets what the "close" button does.
QUESTION 5:
When the program is running:
- How many objects are there?
- Where is the
main()method?