Results 1 to 2 of 2
  1. #1
    siamino is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default JColorChooser modeless - Event Listener problem

    Hi All,

    I'm trying to implement two event listener classes for the OK and Cancel buttons of the JColorChooser Dialog.The compiler is throwing up the following exception:

    MyColourChooser.java:41: cannot find symbol
    symbol : class okListener
    location: class MyColourChooser
    new okListener(),
    ^
    MyColourChooser.java:42: cannot find symbol
    symbol : class cancelListener
    location: class MyColourChooser
    new cancelListener());

    I have defined both of these listeners as inner classes within the main method of my program. Here is the part of my code that I'm having trouble with:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    JButton showButton = new JButton("Choose another colour to draw with");
    showButton.addActionListener(new chooserButtonListener());
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(showButton);
    container.add(buttonPanel, BorderLayout.SOUTH);

    colorChooser = new JColorChooser();
    dialog = JColorChooser.createDialog(
    container,
    "Color Chooser",
    false,
    colorChooser,
    new okListener(),
    new cancelListener());

    // Main Button to show Colour Chooser
    class chooserButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    dialog.show();
    }
    }//close Main button inner class

    // OK Button to pick colour
    class okListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    color = colorChooser.getColor();
    }
    }//close OK button inner class

    // Cancel Button
    class cancelListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    dialog.dispose();
    }
    }//close Cancel button inner class

    ActionListener showListener = new chooserButtonListener();
    showButton.addActionListener(showListener);

    From what I can see the compiler is saying that it cannot find the two event listeners that I'm trying to pass as arguments in the createDialog call. I'm a bit unsure how to solve this.

    Thanks
    Si
    Last edited by siamino; 04-13-2009 at 08:28 PM.

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Try this:

    Java Code:
    
      dialog = JColorChooser.createDialog(
                    container,
                    "Color Chooser",
                    false,
                    colorChooser,
                    new ActionListener() {
    
                        public void actionPerformed(ActionEvent e) {
                            //throw new UnsupportedOperationException("Not supported yet.");
                        }
                    },
                    new ActionListener() {
    
                        public void actionPerformed(ActionEvent e) {
                           // throw new UnsupportedOperationException("Not supported yet.");
                        }
                    });
    Try to put new Actionlisteneres in the method and see if it works...
    Who Cares... As Long As It Works...

Similar Threads

  1. How to use JColorChooser?
    By aRTx in forum New To Java
    Replies: 6
    Last Post: 04-03-2009, 03:50 AM
  2. Replies: 1
    Last Post: 03-31-2009, 04:15 AM
  3. #key listener problem
    By mij1_7 in forum New To Java
    Replies: 2
    Last Post: 02-14-2009, 10:02 PM
  4. Listener for SWT event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 10:04 AM
  5. problem with event handling!!!
    By ahdus in forum Java Applets
    Replies: 1
    Last Post: 11-17-2007, 07:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •