Frame Class

Components

A component is an object that provides Graphical representation for display on the screen. It helps the user to interact with system very efficiently.

For example: buttons, checkboxes, frames etc.

Frame Class

The Frame class is a top level window. The type of window is defined by Frame. It has border and title. Frame() constructor is used to create Frame window.

Declaration of Frame Class

public class Frame
  extends Windwo
      implements MenuCountainer

Frame Class Constructors

i.) Frame() - Constructs new instance of frame.
ii.) Frame(String title) - Constructs the initial frame with specified title.

Example: Creating Frame in AWT

// FrameDemo.java

import java.awt.*;
public class FrameDemo extends Frame
{
    String title;
    public FrameDemo(String title)
    {
        super(title);
        setSize(200, 150);
        setVisible(true);
        setLayout(null);
    }
    public void paint(Graphics g)
    {
        Font font = new Font("Times New Roman", Font.BOLD, 50);
        setForeground(Color.RED);
        g.drawString("Example of Frame.", 50, 50);
    }
    public static void main(String args[])
    {
         new FrameDemo("My First Frame");
    }
}


Output: