import java.awt.*
import javax.swing.*
The *
means to import all the classes in the package.
It is OK (and usual) to do this, even if you only use a few of the classes.
Our first GUI program does not have a listener nor any application code, and is not a useful program. But it will get us started. Here is the complete program:
import java.awt.*; import javax.swing.*; public class TestFrame1 { public static void main ( String[] args ) { JFrame frame = new JFrame("Test Frame 1"); frame.setSize(200,100); frame.setVisible( true ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } }
First a JFrame
is created by invoking its constuctor.
The argument to the constructor sets the title of the frame.
The setSize(200,100)
The setVisible(true)
setVisible(false)
It is easy to forget to include setVisible(true)
The setDefaultCloseOperation()
Can the size of a frame be changed as the program runs by
calling setSize(x,y)