Page 2 :
1.2. Creating windowed programs and, Applets., Working with Frame Windows:, After the applet, the type of window we will most often, , create is derived from Frame., We will use it to create child windows within applets, and, , top-level or child windows for applications., It creates a standard-style window., , Prof. Ghanawajeer D.J.
Page 3 :
1.2. Creating windowed programs and, Applets., ❖ Frame’s Constructors:, , Frame( ) – It creates a standard window that does not, , contain a title., Frame(String title)- It creates a window with the title, , specified by title., Note that we cannot specify the dimensions of the window., Instead, we must set the size of the window after it has been, created., Prof. Ghanawajeer D.J.
Page 4 :
1.2. Creating windowed programs and, Applets., ❖, , Setting the Windows Dimensions:, , The setSize( ) method is used to set the dimensions of the, , window., void setSize(int newWidth, int newHeight), , , void setSize(Dimension newSize), , The new size of the window is specified by ‘newWidth’ and, , ‘newHeight’, or by the ‘width’ and ‘height’ fields of the, Dimension object passed in ‘newSize’., Prof. Ghanawajeer D.J.
Page 5 :
1.2. Creating windowed programs and, Applets., ❖ Setting the Windows Dimensions:, The dimensions are specified in terms of pixels. The getSize( ), , method is used to obtain the current size of a window., , , Dimension getSize( ), , This method returns the current size of the window contained, , within the ‘width’ and ‘height’ fields of a Dimension object., , Prof. Ghanawajeer D.J.
Page 6 :
1.2. Creating windowed programs and, Applets., ❖ Hiding and showing a Window:, After a frame window has been created, it will not be visible, , until we call setVisible( )., void, , setVisible(boolean visibleFlag), , The component is visible if the argument to this method is, , true. Otherwise, it is hidden., , Prof. Ghanawajeer D.J.
Page 7 :
1.2. Creating windowed programs and, Applets., ❖ Setting a Windows Title:, We can change the title in a frame window using setTitle( )., void, , setTitle(String newTitle), , Here, ‘newTitle’ is the new title for the window., , Prof. Ghanawajeer D.J.
Page 8 :
1.2. Creating windowed programs and, Applets., ❖ Closing a Frame Window:, When using a frame window, our program must remove that, , window from the screen when it is closed, by calling, , setVisible(false)., To intercept a window-close event, we must implement the, , windowClosing() method of the WindowListener interface., Inside windowClosing( ), we must remove the window from the, screen., Prof. Ghanawajeer D.J.
Page 9 :
1.2. Creating windowed programs and, Applets., Creating a Windowed Program:, Although creating applets is the most common use for Java’s, , AWT, it is possible to create stand-alone AWT-based applications,, , too., To do this, simply create an instance of the window or windows, , we need inside main( )., , Prof. Ghanawajeer D.J.
Page 10 :
1.2. Creating windowed programs and, Applets., Creating a Windowed Program:, , Example, , Prof. Ghanawajeer D.J.