import awt.*;
import java.awt.*;
import java.awt.event.*;
class Buttoncolor implements ActionListener
{
Frame fr;
Panel p;
Button b1,b2,b3,b4,b5;
Buttoncolor()
{
fr=new Frame("CLICK EVENT ON BUTTON COLOR AWT");
p=new Panel();
b1=new Button("RED");
b2=new Button("GREEN");
b3=new Button("BLUE");
b4=new Button("YELLOW");
b5=new Button("BLACK");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
fr.addWindowListener(new bwclose());
fr.add(p);
fr.setSize(800,800);
fr.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
p.setBackground(Color.red);
}
if(e.getSource()==b2)
{
p.setBackground(Color.green);
}
if(e.getSource()==b3)
{
p.setBackground(Color.blue);
}
if(e.getSource()==b4)
{
p.setBackground(Color.yellow);
}
if(e.getSource()==b5)
{
p.setBackground(Color.black);
}
}
}
class bwclose extends WindowAdapter
{
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
class UseBcolor
{
public static void main(String args[])
{
Buttoncolor obj =new Buttoncolor();
}
}
import java.awt.*;
import java.awt.event.*;
class Buttoncolor implements ActionListener
{
Frame fr;
Panel p;
Button b1,b2,b3,b4,b5;
Buttoncolor()
{
fr=new Frame("CLICK EVENT ON BUTTON COLOR AWT");
p=new Panel();
b1=new Button("RED");
b2=new Button("GREEN");
b3=new Button("BLUE");
b4=new Button("YELLOW");
b5=new Button("BLACK");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
fr.addWindowListener(new bwclose());
fr.add(p);
fr.setSize(800,800);
fr.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
p.setBackground(Color.red);
}
if(e.getSource()==b2)
{
p.setBackground(Color.green);
}
if(e.getSource()==b3)
{
p.setBackground(Color.blue);
}
if(e.getSource()==b4)
{
p.setBackground(Color.yellow);
}
if(e.getSource()==b5)
{
p.setBackground(Color.black);
}
}
}
class bwclose extends WindowAdapter
{
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
class UseBcolor
{
public static void main(String args[])
{
Buttoncolor obj =new Buttoncolor();
}
}
Comments
Post a Comment