Java Abstract Window ToolKit(AWT)
Java Programming

Java Abstract Window ToolKit(AWT)

 

Awt package is used for components and awt. event package is used for action performed. If we want to select only one option we use checkboxes.CheckboxGroup is a set of checkboxes in which we can select only one option(checkbox) . The checkboxes which are set in CheckboxGroup are called “radio buttons”.

AWT Example

import java.awt.*;

import java.awt.event.*;

public class lcdd extends Frame implements ActionListener

{

CheckboxGroup cbb;

Checkbox oo1,ff;

Label l1;

Button oo;

public lcdd()

{

setBackground(Color.pink);

cbb=new CheckboxGroup();

oo1=new Checkbox(“on”,true,cbb);

ff=new Checkbox(“off”,false,cbb);

oo=new Button(“Ok”);

setLayout(null);

l1=new Label(“XCnotes.com”);

l1.setBounds(225,100,100,10);

oo.setBounds(300,500,50,20);

oo1.setBounds(300,450,50,20);

ff.setBounds(370,450,50,20);

add(oo);

add(l1);

add(oo1);

add(ff);

oo.addActionListener(this);

}

public void actionPerformed(ActionEvent eh)//click event on button

{

if(eh.getSource()==oo)//when we click on this button the repaint() called

{

repaint();

}}

public void paint(Graphics gl)

{

if(oo1.getState())

{

gl.drawRect(100,100,300,200);

gl.fillRect(100,100,300,200);

Image piic=Toolkit.getDefaultToolkit().getImage(“awt.jpg”);//pic displayed in the lcd

gl.drawImage(piic,110,110,280,180,this); //draw the image

gl.fillRect(230,300,30,50);

gl.fillOval(170,330,150,100);

}

else

{

gl.drawRect(100,100,300,200);

gl.fillRect(100,100,300,200);

gl.fillRect(230,300,30,50);

gl.fillOval(170,330,150,100);

}

}

public static void main(String aa[])

{

lcdd lc=new lcdd();//lc is the object of class lcdd

lc.setSize(300,300); //we can set the size of the frame by using setSize()

lc.setVisible(true);

lc.addWindowListener(new WindowAdapter()   //for window closing

{

public void windowClosing(WindowEvent ew)  //when we click on close then this event perform

{

System.exit(0); //for closing

}

});

}

}

Abstract Window Toolkit(AWT)

Explanation…

In the above example when we select on the checkbox and click on button then the image will be shown and when we select off checkbox and click on button then the image will not show (like switch on and off)

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment