0% found this document useful (0 votes)
27 views

Java Seminar

Uploaded by

Sandesh M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Java Seminar

Uploaded by

Sandesh M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Seminar on

AWT Controls
AWT Controls
• Java awt(abstract window toolkit)is an API to
develop GUI or window based applications in
java
• Java AWT components are platform
dependent i.e components are displayed
according to the view of opperating system.
• AWT is heavyweight i.e its componets are
using the resources of OS.
• Java.awt package provides classes for AWT api
such as
TextField,Label,TextArea,RadioButton,CheckBo
x,Choice,List etc.
How to add or remove controls?
Create an instance of desired control and then add it to the
window by calling add() method.
Syntax:-
Component add(Component obj)

We can also remove our control from window by calling remove() method.
Syntax:-
Void remove(Component obj)

And also controls can be removed by calling removeAll()


AWT hierarchy
Methods of Component class
AWT button

The button class is used to create a labeled


button that has platform independent
implementation. The application result in some
action when the button is pushed.

AWT Button class declaration


Public class Button extends Component implements Accessible
//java AWT Button example
import java.awt.*;
Public class ButtonExample
{

Public static void main(String args)


{
Frame f=new Frame(“Button example”)
Button b=new Button(“click here”);
b.setBounds(50,100,80,30);
f.add(b);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Java AWT Button Example with ActionListener
import java.awt.*;
import java.awt.event.*;
public class ButtonExample
{
public static void main(String[] args)
{
Frame f=new Frame("Button Example");
final TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new Button("Click Here");
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener());
{
public void actionPerformed(ActionEvent e)
{
tf.setText("Welcome to Javatpoint.");
}
}
f.add(b);
f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Java AWT Label
The object of label class is a computer for
placing text in a container. it is used to display a
single line of read only text. the text can be
changed by an application but a user cannot edit
it directly.

AWT label class declaration:-


Public class Label extends Component implements Accessible
Constructors:

1) Label() – a blank label

2) Label(String str) – str: String to display which is left aligned.

3) Label(String str, int Row) – Row :how the alignment. It’s value
can be set as, Label.LEFT, Label.RIGHT, Label.CENTER

Methods:
setText() : Allows you to set or change the text in a label
getText() : Allows you to obtain the current label.

Syntax:-

void setText(String str)

String getText()
//java Lable Example
Import java .awt.*;
Class LabelExample
{
Public static void main(String args[])
{
Frame f=new Frame(“labelExample”);
Label l1,l2;
L1=new Label(“first label”);
L1.setBounds(50,100,100,30);
L2=new Label(“second label”);
L2.setBounds(50,150,100,30);
f.add(l1);
f.add(l2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
AWT checkbox
The checkbox class is used to create a checkbox.
it is used to turn an option on(true) or
off(false).clicking on a checkbox changes its state
from “on” to “off” or from “off” to “on”.

AWT Checkbox class Declaration:-


Public class Checkbox extends Component implements
itemSelectable,Accessible
//Java AWT Checkbox example
Import java.awt.*;
public class checkboxExample
{
checkboxExample()
{
Frame f=new Frame(“checkbox Example”);
Checkbox1.setBounds(100,100,50,50);
Checkbox checkbox2=new checkbox(“java”,true);
Checkbox2.setBounds(100,150,50,50);
f.add(checkbox1);
f.add(checkbox2);
f.setSize(400,400);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
Public static void main(String args[])
{
New /checkboxExample();
}
}
Thank you

You might also like