/*
* To change this template, choose Tools |
Templates
* and open the template in the editor.
*/
package Swing;
/**
*
* @author Administrator
*/
import java.awt.Color;
import javax.swing.*;
import
java.awt.event.ActionListener;
import
java.awt.event.*;
class Buttoncolor
implements ActionListener
{
JFrame fr;
JPanel p;
JButton b1,b2,b3,b4,b5;
Buttoncolor()
{
fr=new JFrame("CLICK EVENT ON
BUTTON COLOR SWING");
p=new JPanel();
b1=new JButton("RED");
b2=new JButton("GREEN");
b3=new JButton("BLUE");
b4=new JButton("YELLOW");
b5=new JButton("ORANGE");
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 close());
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.orange);
}
}
}
class close 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