Creating Control Programs
1. TextField-
TextField is used for singleLine input.
PROGRAM-
import java.awt.*;
class text1
{
text1()
{
Frame f1 = new Frame("e.g TextBox");
TextField t1 = new TextField("Enter your name");
t1.setBounds(50,100,200,30);
f1.add(t1);
f1.setSize(400,400);
f1.setLayout(null);
f1.setVisible(true);
}
public static void main(String args[])
{
text1 te1 = new text1();
}
}
2. TextArea-
TextArea is used for MultiLine input.
PROGRAM-
import java.awt.*;
class text2
{
text2()
{
Frame f1 = new Frame("Text area example");
TextArea ta1 = new TextArea("WELCOME TO JAVA");
ta1.setBounds(10,30,300,300);
f1.add(ta1);
f1.setSize(400,400);
f1.setLayout(null);
f1.setVisible(true);
}
public static void main(String args[])
{
text2 ta2 = new text2();
}
}
3. Checkbox-
Checkbox is used for multiple selection.
PROGRAM-
import java.awt.*;
class check
{
check()
{
Frame f1 = new Frame("CheckBox");
Checkbox c1 = new Checkbox("python");
c1.setBounds(100,100,50,50);
Checkbox c2 = new Checkbox("java");
c2.setBounds(100,150,50,50);
f1.add(c1);
f1.add(c2);
f1.setSize(400,400);
f1.setLayout(null);
f1.setVisible(true);
}
public static void main(String args[])
{
check ch1 = new check();
}
}
4. Label-
import java.awt.*;
class awt4
{
awt4()
{
Frame f1 = new Frame();
Label l1 = new Label("Enter any number");
l1.setBounds(50,80,80,80);
f1.add(l1);
f1.setSize(400,400);
f1.setLayout(null);
f1.setVisible(true);
}
public static void main(String args[])
{
awt4 a1 = new awt4();
}
}
5.Button-
import java.awt.*;
class awt3
{
awt3()
{
Frame f1= new Frame();
Button b1 = new Button("Click here");
b1.setBounds(50,80,80,80);
f1.add(b1);
f1.setSize(400,400);
f1.setLayout(null);
f1.setVisible(true);
}
public static void main(String args[])
{
awt3 a1 = new awt3();
}
}
Comments
Post a Comment