Java Seminar
Java Seminar
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)
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:-
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”.