A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Java AWT example:

To create simple AWT, you need a frame and there are two ways to create a frame in AWT.
By extending Frame class(inheritance)
By creating the object of Frame class(association)

Simple example of AWT(by inheritance)

// use AWT package
Import java.awt*;

Class Diamond extend Frame{
Button b = new Button (“click me”);

// the setBounds( int x-axis, int y-axis, int width, int height) method is using in this example that sets the position of awt button.
//set button position
b.setBounds(35, 120, 85, 30);

//add button into frame

//Frame size is as 280 width and 280 height

//no layout manager

//now frame will be visible, since by default frame will not be visible


public static void main ( String args[])
           Diamond d = new Diamond ( );