Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2009, 07:37 PM
Member
 
Join Date: Apr 2009
Posts: 10
Rep Power: 0
siamino is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-14-2009, 01:39 AM
markw8500's Avatar
Senior Member
 
Join Date: Jul 2008
Location: Pennsylvania, USA
Posts: 136
Rep Power: 0
markw8500 is on a distinguished road
Default
Try this:

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...
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use JColorChooser? aRTx New To Java 6 04-03-2009 03:50 AM
How to color a rectangle throught JColorChooser? aRTx New To Java 1 03-31-2009 04:15 AM
#key listener problem mij1_7 New To Java 2 02-14-2009 10:02 PM
Listener for SWT event Java Tip Java Tips 0 01-08-2008 10:04 AM
problem with event handling!!! ahdus Java Applets 1 11-17-2007 07:24 PM


All times are GMT +2. The time now is 05:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org