AWT  concept

AWT concept:
AWT stands for Abstract Window Toolkit. It is a portable GUI library among various operating systems for standalone applications.
The Abstract Window toolkit provides many classes for programmers to use. the java programming language class library provides a user interface toolkit called the Abstract Windowing Toolkit, or the AWT. the AWT is both powerful and flexible.
Types of Components:
the AWT provides nine basic non-container component classes from which a user interface may be constructed.These nine classes are class Button,Canvas,Checkbox,Choice,Label,List,Scrollbar,TextArea,and TextField.

  1. AWT(Displaying Button Using AWT)
import java.util*;
import java.awt.*;
class First extends Frame
{ 
First()
{ 
Button b=new Button("click me"); 
b.setBounds(30,100,80,30);
// setting button position 
add(b);
//adding button into frame 
setSize(300,300);
//frame size 300 width and 300 height
 setLayout(null);
//no layout manager 
setVisible(true);//now frame will be visible, by default not visible 
} 
public static void main(String args[])
{
 First f=new First(); 
}
} 
OUTPUT:
Displaying Button Using AWT
Displaying Button Using AWT

2.SECOND EXAMPLE OF AWT(Extends the Frame and Display the Button)

import java.util.*;
import java.awt.*; 
/* We have extended the Frame class here, * thus our class "SimpleExample" would behave * like a Frame */ 
public class SimpleExample extends Frame{ 
SimpleExample()
{
 Button b=new Button("Button!!");
 // setting button position on screen 
b.setBounds(50,50,50,50);
 //adding button into frame 
add(b);
 //Setting Frame width and height
 setSize(500,300); 
//Setting the title of Frame 
setTitle("This is my First AWT example");
 //Setting the layout for the Frame 
setLayout(new FlowLayout());
 /* By default frame is not visible so * we are setting the visibility to true * to make it visible. */
 setVisible(true);
 }
 public static void main(String args[])
{ 
// Creating the instance of Frame SimpleExample 
fr=new SimpleExample();
 }
 }
OUTPUT:
Extends the Frame and Display the Button
Extends the Frame and Display the Button
Translate »