AWT Controls
AWT Controls
E.BRUMANCIA
ASSISTANT PROFESSOR
DEPT OF INFORMATION TECHNOLOGY
SCHOOL OF COMPUTING
SATHYABAMA INSTITUTE OF SCIENCE AND TECHNOLOGY
TOPICS TO BE COVERED
• CONTROL FUNDAMENTALS
• LABELS
• BUTTONS
• CHECKBOXES
• CHECKBOXGROUP
• LISTS
• SCROLL BARS
• LAYOUT MANAGERS
• FLOW LAYOUT
• CARD LAYOUT
• GRID LAYOUT
• BORDER LAYOUT
ABSTRACT WINDOW TOOLKIT
import java.awt.*;
import java.applet.*;
/*
<applet code=“Labeldemo" width=300 height=200>
</applet>
*/
public class Labeldemo extends Applet
{
public void init()
{
label one = new label("one");
label two = new label("two");
label three = new label("three");
// add labels to applet window
add(one);
add(two);
add(three);
}
}
BUTTONS
TextComponent
TextArea TextField
TextArea( )
TextArea(int numLines, int TextField( )
numChars) TextArea(String str) TextField(int numChars)
TextArea(String str, int numLines, int TextField(String str)
numChars) TextField(String str,
TextArea(String str, int numLines, int intnumChars)
numChars, int sBars
Example for Textfield
Import java.awt.*;
Import java.applet.*;
/*
<Applet code="textfielddemo" width=380 height=150>
</Applet>
*/
Public class textfielddemo extends Applet
{
Textfield name, pass;
public void init()
{
Label namep = new label("name: ", label.RIGHT);
label passp = new label("password: ", label.RIGHT); name = new textfield(12);
Pass = new textfield(8); pass.Setechochar('?’); add(namep);
add(name); add(passp); add(pass);
}
Public void paint(graphics g)
{
}
}
TEXT AREA
Import java.Awt.*;
Import java.Applet.*;
/*
<Applet code="textareademo" width=300 height=250>
</Applet>
*/
Public class textareademo extends applet
{
Public void init()
{
String val = "there are two ways of constructing " + "a software design.\N" +
"one way is to make it so simple\n" +
"that there are obviously no eficiencies.\N" + "and the other way is to make it so complicated\n" + "that there
are no obvious deficiencies.\N\n" +
" -C.A.R. Hoare\n\n" +
"there's an old story about the person who wished\n" + "his computer were as easy to use as his telephone.\N" +”;
Textarea text = new textarea(val, 10, 30);
Add(text);
}
}