Basic AWT components
AWT: Abstract Window Toolkit
Its’s built-in platform-independent windowing, graphics, and user-interface widget toolkit. The java.awt is now part of the Java Foundation Classes (JFC). Which can be used for a graphical user interface (GUI) for a Java program. AWT consists of many classes which can be said: Components. A component is a class which can create a event specific GUI like TextField, Button, Label, Checkbox, TextArea, etc…
To add any component in Applet area, We have to call a add(Component c) method of Applet class. Which is discussed briefly in the below example.
import java.applet.*;
import java.awt.*;
public class componentDemo extends Applet
{
Button b;
Label l;
TextField tf;
Scrollbar sb;
TextArea ta;
Checkbox c1,c2,c3;
CheckboxGroup cbg = new CheckboxGroup();
public void init()
{
tf = new TextField("Ankit",20);
l = new Label("First Name:");
b = new Button("Okay!");
ta = new TextArea(7,40);
sb = new Scrollbar(Scrollbar.VERTICAL, 100, 20, 0, 200);
sb.setPreferredSize(new Dimension(30,200));
c1 = new Checkbox("Cricket",true,cbg);
c2 = new Checkbox("Hockey",false,cbg);
c3 = new Checkbox("Football",false,cbg);
add(l);
add(tf);
add(b);
add(sb);
add(ta);
add(c1);
add(c2);
add(c3);
}
}
/*
<applet code="componentDemo" width="500" height="500"></applet>
*/
Output:





Recent Comments