You are on page 1of 6

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 com.company;
import java.awt.*;

public class awt1 {


awt1(){
Frame frame = new Frame();

Label l = new Label("SOMETHING");


l.setBounds(20,50,80,30);
frame.add(l);

Button b = new Button("SUBMIT");


b.setBounds(20,100,80,30);
frame.add(b);

TextField t = new TextField();


t.setBounds(100,100,80,30);
frame.add(t);

frame.setSize(400,300);
frame.setTitle("AWT Example (By Association)");
frame.setLayout(null);
frame.setVisible(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 com.company;

import java.awt.*;

public class awt2 extends Frame {


awt2(){
Label l = new Label("Something");
l.setBounds(20,50,80,30);
add(l);

Button b = new Button("Submit");


b.setBounds(20,80,80,30);
add(b);

TextField t = new TextField();


t.setBounds(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 com.company;

import java.awt.*;

public class awt3 extends Frame {


awt3(){

setSize(600,600);
setTitle("Awt Example (By inheritance)");
setLayout(null);
setVisible(true);
}

public void paint(Graphics g){


g.setColor(Color.BLUE);
g.drawLine(20,80,60,100);
g.drawRect(30,40,50,70);

g.setColor(Color.RED);
g.drawOval(110,70,30,80);
//g.setColor(Color.MAGENTA);
Color myColor = new Color(100,255,100);
g.setColor(myColor);
g.fillOval(90,200,80,80);

String fontName = "Comic Sans MS";


int fontStyle = Font.BOLD;
int fontSize = 34;
Font font1 = new Font(fontName,fontStyle,fontSize);
g.setFont(font1);
g.setColor(Color.MAGENTA);
g.drawString("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 com.company;

import java.awt.*;
public class awt4
{
awt4(){
Frame f= new Frame("AWT Controls Example");

CheckboxGroup cbg = new CheckboxGroup();


Checkbox checkBox1 = new Checkbox("C++", cbg, false);
checkBox1.setBounds(200,100, 50,50);
Checkbox checkBox2 = new Checkbox("Java", cbg, true);
checkBox2.setBounds(200,150, 50,50);
f.add(checkBox1);
f.add(checkBox2);

Checkbox c1 = new Checkbox("YES",true);


c1.setBounds(100,100,50,50);
f.add(c1);
Checkbox c2 = new Checkbox("NO",false);
c2.setBounds(100,150,50,50);
f.add(c2);

List myList = new List();


myList.add("CST",1);
myList.add("ME",2);
myList.add("EE",3);
myList.setBounds(150,200,50,50);
f.add(myList);

Choice myChoice = new Choice();


myChoice.add("CSE");
myChoice.add("ME");
myChoice.add("EE");
myChoice.setBounds(250,200,50,50);
f.add(myChoice);

TextArea ta = new TextArea();


ta.setBounds(100,300,200,200);
f.add(ta);

f.setSize(600,600);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new awt4();
}
}

OUTPUT

You might also like