Skip to Content

Create Frame Window Example

  1. /*
  2.         Create Frame Window Example
  3.         This java example shows how to create frame window using Java AWT.
  4. */
  5.  
  6. import java.awt.Frame;
  7.  
  8. /*
  9.  * To create a stand alone window, class should be extended from
  10.  * Frame and not from Applet class.
  11.  */
  12. public class CreateFrameWindowExample extends Frame{
  13.  
  14.         CreateFrameWindowExample(String title){
  15.                
  16.                 //call the superclass constructor
  17.                 super();
  18.                
  19.                 //set window title using setTitle method
  20.                 this.setTitle(title);
  21.                
  22.                 /*
  23.                  * Newly created window will not be displayed until we call
  24.                  * setVisible(true).
  25.                  */
  26.                 this.setVisible(true);
  27.         }
  28.        
  29.         public static void main(String args[]){
  30.                 CreateFrameWindowExample window =
  31.                                 new CreateFrameWindowExample("Create Window Example");
  32.                
  33.                 /*
  34.                  * In order to close the window, we will have to handle the events
  35.                  * and call setVisible(false) method.
  36.                  *
  37.                  * This Example program does not handle events, so you will have
  38.                  * to terminate the program (by pressing ctrl+C) in a terminal window
  39.                  * to close the frame window.
  40.                  */
  41.         }
  42. }

Example Output