Apr 16, 2012

Frame


The Frame class provides windows for Applets and Applications. The following program illustrates  the frame.

Example:

import java.awt.*;
class frameDemo
{
Public static void main(String[] args)
{
     Frame f=new Frame(“This is my frame”);
     f.setBackground(Color.red);
     f.setSize(300,300);
     f.setVisible(true);
     System.out.println(“Return to DOS prompt and press control+c to quit”);
}
}

Explanation:
       In the above program we created a frame, and set the title as “This is my frame”. To determine the size of frame by setSize() method and set the Background color by setBackground() method. The size is 300 pixels wide and 100 pixel high. The frame invoke the setVisible() method to display the frame window.
 The frame cannot be destroyed directly. So come to DOS prompt and press control+C to quit.

The above program can be written as follows

import java.awt.*;
class myFrame extends Frame
{
myFrame()
        {
             super(“This is my frame”);
             setBackground(Color.red);
             setSize(300,300);
             setCursor(Frame.HAND_CURSOR);
             show();
        }

        public static void main(String[] args)
        {
             new myFrame();
             System.out.println(“Return to DOS prompt and press ctrl+C to quit”);
        }
}

output:



The frame class consist of a method setCursor(int), it is used to set type of cursor. The cursor must be in one of the following type. It is deprecated method.

DEFAULT_CURSOR
TEXT_CURSOR
SW_RESIZE_CURSOR
NW_RESIZE_CURSOR
N_RESIZE_CURSOR
W_RESIZE_CURSOR
HAND_CURSOR
NORMAL
CROSSHAIR_CURSOR
WAIT_CURSOR
SE_RESIZE_CURSOR
NE_RESIZE_CURSOR
S_RESIZE_CURSOR
E_RESIZE_CURSOR
MOVE_CURSOR
ICONIFIED



0 comments :

Post a Comment