Problem with activeListener interface

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rawinder dhillon
    New Member
    • Oct 2006
    • 8

    Problem with activeListener interface

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



    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);
    		
    	}
    }
    Last edited by pbmods; Mar 2 '09, 12:19 AM. Reason: Added CODE tags.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by rawinder dhillon
    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

    Comment

    • rawinder dhillon
      New Member
      • Oct 2006
      • 8

      #3
      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

      Comment

      Working...