Tuesday 15 November 2016

WORKING WITH FRAMES



  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 stand-alone application.
  Two of frame’s constructors are:
Frame()
Frame(String title)
The first form creates a standard window that does not contain a title. The second form creates a window with the title specified by title. Notice that we cannot specify the dimensions of the window. We must set the size of the window after it has been created. There are several key methods we will use when working the Frame windows. They are:
  Setting the Windows Dimension: The setSize() method is used to set the dimensions the window.
                   void setSize(int newWidth, int newHeight )
                   void setSize(Dimention newSize)
            The new size of the window is specified by newWidth and newHeight.
The getSize() method is used to obtain the current size of a window.
                   Dimension getSize()
This method return the current size of the window contained within the width and height fields of a dimension object.
  Hiding and Showing a window: After a frame window has been created, it will not be visible until we call the setVisible() .
                               void  setVisible(boolen visibleFlag)
The component is visible if the argument to this method is true. Otherwise it is hidden. 
  Setting a window’s Title: We can change the title in a frame window using setTitle(), which has this general from:
                   void setTitle(String newTitle)
            Here, newTitle is the new title of the window.
  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).The window close event must implement the windowClosing() method of the WindowListener interface.
  Creating a frame window in an Applet:  
            import java.awt.Frame;
            public class CreateFrameWindowExample extends Frame
           {
             CreateFrameWindowExample(String title)
              {
              super();        
              this.setTitle(title);
              this.setVisible(true);
              }
                  
                    public static void main(String args[]){
                            CreateFrameWindowExample window =
                                            new CreateFrameWindowExample("Create Window Example");
                           
                    }
            }

No comments:
Write comments