Advanced Java Programs
1. Use Java AWT package to create a frame (By making a Frame object
(Association)) and add these controls -> a) Label b) Button c) TextField
package [Link];
import [Link].*;
public class awt1 {
awt1(){
Frame frame = new Frame();
Label l = new Label("SOMETHING");
[Link](20,50,80,30);
[Link](l);
Button b = new Button("SUBMIT");
[Link](20,100,80,30);
[Link](b);
TextField t = new TextField();
[Link](100,100,80,30);
[Link](t);
[Link](400,300);
[Link]("AWT Example (By Association)");
[Link](null);
[Link](true);
public static void main(String[] args) {
awt1 obj = new awt1();
}
}
OUTPUT
2. Use Java AWT package to create a frame (By extending the Frame class
(Inheritance)) and add these controls -> a) Label b) Button c) TextField
package [Link];
import [Link].*;
public class awt2 extends Frame {
awt2(){
Label l = new Label("Something");
[Link](20,50,80,30);
add(l);
Button b = new Button("Submit");
[Link](20,80,80,30);
add(b);
TextField t = new TextField();
[Link](100,100,80,30);
add(t);
setSize(400,300);
setTitle("Awt Example (By Inheritance)");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
awt2 obj = new awt2();
}
}
OUTPUT
3. Draw a Line, a Rectangle, an Oval using java AWT package. Colour them
with your choice of colours. Also, write a line of text and change its font, size,
and style.
package [Link];
import [Link].*;
public class awt3 extends Frame {
awt3(){
setSize(600,600);
setTitle("Awt Example (By inheritance)");
setLayout(null);
setVisible(true);
}
public void paint(Graphics g){
[Link]([Link]);
[Link](20,80,60,100);
[Link](30,40,50,70);
[Link]([Link]);
[Link](110,70,30,80);
//[Link]([Link]);
Color myColor = new Color(100,255,100);
[Link](myColor);
[Link](90,200,80,80);
String fontName = "Comic Sans MS";
int fontStyle = [Link];
int fontSize = 34;
Font font1 = new Font(fontName,fontStyle,fontSize);
[Link](font1);
[Link]([Link]);
[Link]("THIS IS A SIMPLE TEXT",100,400);
}
public static void main(String[] args) {
awt3 obj = new awt3();
}
OUTPUT
4. Create a java frame using java AWT package and add these controls->
a) Radio Buttons b) Checkboxes c) List d) Choice Menu e) Text Area
package [Link];
import [Link].*;
public class awt4
{
awt4(){
Frame f= new Frame("AWT Controls Example");
CheckboxGroup cbg = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("C++", cbg, false);
[Link](200,100, 50,50);
Checkbox checkBox2 = new Checkbox("Java", cbg, true);
[Link](200,150, 50,50);
[Link](checkBox1);
[Link](checkBox2);
Checkbox c1 = new Checkbox("YES",true);
[Link](100,100,50,50);
[Link](c1);
Checkbox c2 = new Checkbox("NO",false);
[Link](100,150,50,50);
[Link](c2);
List myList = new List();
[Link]("CST",1);
[Link]("ME",2);
[Link]("EE",3);
[Link](150,200,50,50);
[Link](myList);
Choice myChoice = new Choice();
[Link]("CSE");
[Link]("ME");
[Link]("EE");
[Link](250,200,50,50);
[Link](myChoice);
TextArea ta = new TextArea();
[Link](100,300,200,200);
[Link](ta);
[Link](600,600);
[Link](null);
[Link](true);
}
public static void main(String args[])
{
new awt4();
}
}
OUTPUT