Ads

Tuesday 23 October 2012

AWT CONTROL


PROGRAMS

CHECK BOX:
import java.awt.*;
import java.awt.event.*;
class checkbox extends Frame implements ActionListener,ItemListener
{
Checkbox x,y,z;
CheckboxGroup a;
Button b1;
public checkbox()
{
b1=new Button("EXIT");
setLayout(new FlowLayout());
a=new CheckboxGroup();
x=new Checkbox("CSE");
y=new Checkbox("IT");
z=new Checkbox("ECE");
add(x);
add(y);
add(z);
add(b1);
x.addItemListener(this);
y.addItemListener(this);
z.addItemListener(this);
setLocation(100,100);
show();
b1.addActionListener(this);}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("EXIT"))
{
System.exit(1);
}}
public void itemStateChanged(ItemEvent e)
{
System.out.println("CSE"+x.getState());
System.out.println("IT"+y.getState());
System.out.println("ECE"+z.getState());
}
public static void main(String ar[])
{
checkbox c=new checkbox();
} }


CHOICE:

import java.awt.*;
import java.awt.event.*;
class choice extends Frame implements ActionListener,ItemListener{
Button b1;
Choice c;
public choice(){
b1=new Button("EXIT");
c=new Choice();
c.add("Green");
c.add("Red");
c.add("Blue");
c.add("Gray");
add(c);
add(b1);
b1.addActionListener(this);
c.addItemListener(this);}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("EXIT")){
System.exit(1);
}}
public void itemStateChanged(ItemEvent b1)
{
if(c.getSelectedItem().equals("Green"))
{
setBackground(Color.green);
}
else if(c.getSelectedItem().equals("Red"))
{
setBackground(Color.red);
}
else if(c.getSelectedItem().equals("Blue")){
setBackground(Color.blue);}
else if(c.getSelectedItem().equals("Gray")){
setBackground(Color.gray);
}}
public static void main(String args[]){
choice t=new choice();
t.setLayout(new FlowLayout());
t.setSize(200,200);
t.setLocation(100,100);
t.show();
}}

LIST:

import java.awt.*;
import java.awt.event.*;
class list extends Frame implements ActionListener
{
Button b1;
public list()
{
b1=new Button("EXIT");
add(b1);
List lst=new List(4,false);
lst.add("CSE");
lst.add("IT");
lst.add("ECE");
lst.add("EEE");
lst.add("CHEM");
add(lst);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("EXIT"))
{
System.exit(1);
}
}
public static void main(String args[])
{
list l=new list();
l.setLayout(new FlowLayout());
l.setSize(400,200);
l.setLocation(100,100);
l.show();
}
}

SCROLL:

import java.awt.*;
import java.awt.event.*;
class Demo extends Frame implements ActionListener
{
Scrollbar sc=new Scrollbar();
Button b1;
public Demo()
{
b1=new Button("EXIT");
add(b1);
FlowLayout f1=new FlowLayout();
setLayout(f1);
add(sc);
b1.addActionListener(this);
setSize(500,500);
show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("EXIT"))
{
System.exit(1);
}
}
}

class Scroll
{
public static void main(String args[])
{
Demo s=new Demo();
}
}

TEXT:

import java.awt.*;
import java.awt.event.*;
class text extends Frame implements ActionListener
{
FlowLayout f=new FlowLayout();
TextField t1=new TextField(10);
TextField t2=new TextField(10);
Button b=new Button("COPY");
Button b1=new Button("EXIT");
public text()
{
setLayout(f);
setSize(600,400);
setLocation(200,200);
add(t1);
add(t2);
b.addActionListener(this);
add(b);
b1.addActionListener(this);
add(b1);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("COPY"))
{
t2.setText(t1.getText());
}
else if(e.getActionCommand().equals("EXIT"))
{
System.exit(1);
}
}
public static void main(String args[])
{
text t1=new text();
}
}






No comments:

Post a Comment