Adanced Java Programming
AWT User Interface Controls
Smt.M.Jeevana Sujitha
Assistant Professor
Department of Computer Science and Engineering
SRKR Engineering College, Bhimavaram, A.P. - 534204
OBJECTIVES
The Objective of this lecture is
AWT User Interface Controls
that allows us to write a single line text.
Example:
TextField t1=new TextField(10);
Method and Description
public void add(Component c)
inserts a component on this component.
public void setSize(int width,int height)
sets the size (width and height) of the component.
public void setLayout(LayoutManager m)
defines the layout manager for the component.
public void setVisible(boolean status)
changes the visibility of the component, by default false.
setBounds(int x-coordinate, int y-coordinate, int width, int height)
The first two arguments are x and y coordinates of the top-left corner of the component, the third argument is the width of the component and the fourth argument is the height of the component.
Example program
import java.awt.*;
class TextFieldExample
{
public static void main(String args[])
{
Frame f= new Frame("TextField Example");
TextField t1,t2;
t1=new TextField("Welcome to Java awt");
t1.setBounds(50,100, 200,30);
t2=new TextField("AWT Tutorial");
t2.setBounds(50,150, 200,30);
f.add(t1);
f.add(t2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
AWT User Interface Controls
import java.awt.*;
class LabelExample
{
public static void main(String args[])
{
Frame f= new Frame("Label Example");
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);
}
}
The text can be changed by an application but an end user
can not edit it directly.
Example:
Label l1=new Label(“Enter user name”);
AWT User Interface Controls
Button: The Button class is used to create a labeled
button that has platform independent implementation.
Example:
Button b1=new Button(“login”);
AWT User Interface Controls
Example:
TextArea ta=new TextArea(“palakollu”);
is used when more than one option is required to be selected.
Example:
Checkbox c1=new Checkbox(“cse", true);
creating radio button in AWT. But we can create it by using
CheckboxGroup.
Example:
CheckboxGroup cg=new CheckboxGroup(); Checkbox c1=new Checkbox(“male”, cg, true); Checkbox c2=new Checkbox(“female”, cg, false);
AWT User Interface Controls
can choose either one or multiple items.
Example:
List l=new List(3,true); l.add(“c”);
l.add(“cpp”);
l.add(“java”);
l.add(“wt”);
from a list of available choices.
Example:
Choice ch=new Choice(); ch.add(“hyd”);
ch.add(“pkl”);
ch.add(“bvrm”)
AWT User Interface Controls
Example:
Scrollbar s=new Scrollbar(); s.setBounds(100,100,50,50); add(s);
THANK YOU