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