Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Course: Advanced Java, Prepared By: Atul Kabra, 9422279260

Adv. Java Lecture-2

Topic: Drawing Graphics inside Frame and AWT Component Hierachy


 Drawing Graphics Inside Frame:
There are different ways to draw graphics inside frame but most common
method is to override the paint method in Frames subclass.

Following program draw graphics inside Frame

import java.awt.*;

class GraphicsFrame extends Frame //Making subclass of Frame


{
GraphicsFrame() //Constructor
{
setSize(600,600);
setTitle("Graphics Frame");
}

public void paint(Graphics g) //overriding paint method of Frame class


{
g.setFont(new Font("Arial",Font.BOLD,20));
g.drawString("Drawing Graphics inside Frame",50,100);
g.drawLine(50,110,400,110);
g.setColor(Color.RED);
g.fillOval(50,200,200,200);
}

public static void main(String [] args)// program execution starts from here
{
GraphicsFrame f = new GraphicsFrame(); //creating Frame Object
f.setVisible(true);
}
}

Course: Advanced Java, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Advanced Java, Prepared By: Atul Kabra, 9422279260

Output:

AWT Comonent & Container :


 In Java, a component is the basic user interface object and is found in all
Java applications. Components include lists, buttons, panels, and windows.

 To use components, you need to place(add) them in a container.

 A container is a component that holds and manages other components.


Containers display components using a layout manager.

Component & Container

Choice Component
Label
Component Button Component

Course: Advanced Java, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Advanced Java, Prepared By: Atul Kabra, 9422279260

AWT Comonent & Container classes Hierarchy (Inheritance):

Object

Course: Advanced Java, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260

You might also like