Saturday 28 April 2018

Abstract Window toolkit (AWT) in java

Abstract Window toolkit (AWT)

The abstract window toolkit(AWT) is a library of java packages that forms part of the java API.It includes over 25 packages that define hundreds of classes used for Graphical User Interface(GUI).
The awt classes contained in the java.awt. package. The following diagram illustrate the component hierarchy.

This package provides an integrated set of classes to manage user interface components like windows dialog boxes button checkbox lists menus, scrollbars and text fields. the component class which implements the common functionality is the super class for all GUI elements.Every component has a unique container that directly contains it.A container is a window like component that can contain other components it has special properties including layout manger and insets. it is a subclass of component a window class creates top level window it sits directly on the desktop it is subclass of container a frame is subclass ow window and has a title bar menu bar a cursor and an icon image.
whit help of components are creating good and better GUI for any application.Java provides awt kits that is very special for desktop application based on Graphical user interface.
Every component has won unique properties and features.

To add awt package in your java programs using import header with java.awt package.
after importing package necessary you declared every component in your java program.
after declaration you add component in your application .to add component of at following these
steps.
1.import java.awt. *; in header line.
2.declared component like this.
for Button component
Button b;
for label component
Label l;
if you declared component of awt kit you remember these must
(a)Must make first later in capital from 
(b)Must every variable is meaning full like for Button component
write like this
Button Button1 or b1 or b;
3.affter declaration you set properties by new tag
like this
b=new Button ("Click me");
and
b. setSize (200,200);
Here sees a simple example of awt components
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package awtcamponent;
import java.awt.*;
/**
 *
 * @author rajesh kumar shukla
 */
public class Awtcamponent {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        GridBagLayout lyo=new GridBagLayout();
        
        Frame f=new Frame("java awt camponent");
        Button b=new Button("click me");
        Label l=new Label("Enter your name");
        TextField ta=new TextField("Enter name here");
        TextArea taa=new TextArea("Enter more text here") ;
         List li=new List();
         li.add("one");
         li.add("two"); 
         li.add("one");
         li.add("two");        
         li.add("one");
         li.add("two");        
Checkbox ch=new Checkbox();


    Choice cho=new Choice();
    cho.add("student");
    cho.add("teacher");
    f.add(li);
    f.add(ch);
    f.add(cho);
        f.add(taa);
        f.add(ta);
        f.add(l);
        f.add(b);
        f.setVisible(true);
        f.setSize(500,500);
        f.setLayout(lyo);
    }
    
}

0 comments:

Post a Comment