Window and Frame
A window represents any imaginary rectangular area on the screen without any borders or title bar. A frame represents a window with some title and borders.In any application, we create frames to represent various screens where the user can type some data for the application and output screens where the result may be displayed in a particular form. Such screens are nothing but frames only.
Creating a Frame
A frame becomes the basic component in AWT. The frame has to be created before any other component. The reason is that all other components can be displayed in
a frame. There are three ways to create a frame, which are as follows:
1) Create a Frame class object,
Frame f = new Frame();
2) Create a Frame class object and pass its title also,
Frame f = new Frame("My Frame");
3) The third way is to create a subclass MyFrame to the Frame class and create and object to the subclass as:
class MyFrame extends Frame
MyFrame f= new MyFrame();
Since, MyFrame is a subclass of Frame class, its object f contains a copy of Frame class hence f represents the frame. In all these cases, a frame with initial size of 0 pixels width and 0 pixels height will be created, which is not visible on the screen, You may be wondering what these pixels are. A pixel (Short for picture element) represents any single point or dot on the screen. Any data or pictures which are displayed on the screen are composed of several dots called pixels. Nowadays, monitors can accommodate 800 pixels horizontally and 600 pixels vertically. So the total pixels seen on one screen would be 800x768 pixels resolution.
Since, the size of our frame would be 0px height, it is ot visible and hence we should increase its size so that it would be visible to us. This is done by setSize() method, as:
Here, the frame's width is set to 400px and height to 350px. Then, we can display the frame, using setVisible() method, as:
Small Program to create a frame by creating an object to Frame class.
//Creating a frame
public static void main(String args)
//create a frame
Frame f = new Frame("My AWT frame");
//set the size of the frame
//display the frame f.setVisible(true);