Connecting Tech Pros Worldwide Help | Site Map

Problem with activeListener interface

Newbie
 
Join Date: Oct 2006
Posts: 8
#1: Mar 1 '09
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....



Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class buttonTest {
  5.  
  6.     /**
  7.      * @param args
  8.      */
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.         fr f=new fr();
  12.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         f.setVisible(true);
  14.     }
  15. }
  16. class fr extends JFrame
  17. {
  18.     public fr()
  19.     {
  20.         setTitle("Rawinder Dhillon");
  21.         setSize(500,500);
  22.         pa p=new pa();
  23.         add(p);
  24.     }
  25. }
  26. class pa extends JPanel
  27. {
  28.     public pa()
  29.     {
  30.         JButton yb=new JButton("Yellow");
  31.         JButton bb=new JButton("Blew");
  32.         JButton rb=new JButton("Red");
  33.  
  34.         add(yb);
  35.         add(bb);
  36.         add(rb);
  37. // now button actions 
  38.         ColorAction ya=new ColorAction(Color.YELLOW);// patrameter in costr. 
  39.         ColorAction ba=new ColorAction(Color.BLUE);
  40.         ColorAction ra=new ColorAction(Color.RED);
  41.  
  42.     // associate action with buttins 
  43.  
  44.         yb.addActionListener(ya);
  45.         bb.addActionListener(ba);
  46.         rb.addActionListener(ra);
  47.     }
  48. }
  49. public class ColorAction implements ActionListener
  50. {
  51.     private Color bg;
  52.     public ColorAction(Color c)
  53.     {
  54.         bg=c;
  55.     }
  56.     public void actonPerformed(ActionEvent event)
  57.     {
  58.         setBackground(bg);
  59.  
  60.     }
  61. }
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Mar 1 '09

re: Problem with activeListener interface


Quote:

Originally Posted by rawinder dhillon View Post

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....

Why don't you at least tell us what the problems are? You don't want us to blindy guess do you? btw, the name of the method is not ActonPerformed.

kind regards,

Jos
Newbie
 
Join Date: Oct 2006
Posts: 8
#3: Mar 2 '09

re: Problem with activeListener interface


thanks for checking but i have found the problem iin the code the class color acrtion was a inner class and " { }" are the problemmm... thanks
Reply