It creates an object of the class JFrame
and gives the frame a title.
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 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 ( WindowConstants.EXIT_ON_CLOSE ); // 7. say what the close button does } }
Here is an explanation of the program:
JFrame
object is constructed.frame
refers to the JFrame
object.setSize()
method sets its size.setVisible()
method makes it appear on the screen.setDefaultCloseOperation()
sets what the "close" button does.When the program is running:
main()
method?