Results 1 to 2 of 2
- 04-13-2009, 06:37 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 10
- Rep Power
- 0
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
SiLast edited by siamino; 04-13-2009 at 07:28 PM.
- 04-14-2009, 12:39 AM #2
Try this:
Try to put new Actionlisteneres in the method and see if it works...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."); } });Who Cares... As Long As It Works...
Similar Threads
-
How to use JColorChooser?
By aRTx in forum New To JavaReplies: 6Last Post: 04-03-2009, 02:50 AM -
How to color a rectangle throught JColorChooser?
By aRTx in forum New To JavaReplies: 1Last Post: 03-31-2009, 03:15 AM -
#key listener problem
By mij1_7 in forum New To JavaReplies: 2Last Post: 02-14-2009, 09:02 PM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM -
problem with event handling!!!
By ahdus in forum Java AppletsReplies: 1Last Post: 11-17-2007, 06:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks