Hi friends ..
i was writing a program that use three buttos and change its color when we click on a particuler button... but its not working their is some problem with activeListener interface i am giving code with it please help....
i was writing a program that use three buttos and change its color when we click on a particuler button... but its not working their is some problem with activeListener interface i am giving code with it please help....
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class buttonTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
fr f=new fr();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
class fr extends JFrame
{
public fr()
{
setTitle("Rawinder Dhillon");
setSize(500,500);
pa p=new pa();
add(p);
}
}
class pa extends JPanel
{
public pa()
{
JButton yb=new JButton("Yellow");
JButton bb=new JButton("Blew");
JButton rb=new JButton("Red");
add(yb);
add(bb);
add(rb);
// now button actions
ColorAction ya=new ColorAction(Color.YELLOW);// patrameter in costr.
ColorAction ba=new ColorAction(Color.BLUE);
ColorAction ra=new ColorAction(Color.RED);
// associate action with buttins
yb.addActionListener(ya);
bb.addActionListener(ba);
rb.addActionListener(ra);
}
}
public class ColorAction implements ActionListener
{
private Color bg;
public ColorAction(Color c)
{
bg=c;
}
public void actonPerformed(ActionEvent event)
{
setBackground(bg);
}
}
Comment