I'm trying to make a applet that displays a drawing area with radio buttons that create different shapes, but I keep getting the error.
FanGraphicswindow.java:43: FanGraphicswindow.RadioButtonListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
This is my first time experimenting with action listeners so I'm not sure what the problem is. I seem to have done what my Java book has told me to do, and removing the "Implements ActionListener" gives me the error
FanGraphicswindow.java:38: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (FanGraphicswindow.RadioButtonListener)
Any ideas what I did wrong? From what I've read online its either not using a method or a misspelling of some sort, but I don't see any of that in my code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FanGraphicsWindow extends JApplet
{
private JRadioButton[] radioButtons;
private String[] titles = { "Off", "Low",
"Medium", "High" };
private ButtonGroup radioButtonGroup;
private JPanel radioPanel;
private int timeDelay = 30;
private DrawingPanel drawingPanel;
public void init()
{
buildRadioPanel();
drawingPanel = new DrawingPanel(radioButtons);
add(radioPanel, BorderLayout.EAST);
add(drawingPanel, BorderLayout.CENTER);
}
private void buildRadioPanel()
{
radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(4,1));
radioButtonGroup = new ButtonGroup();
radioButtons = new JRadioButton[4];
for (int i = 0; i < radioButtons.length; i++)
{
radioButtons[i] = new JRadioButton(titles[i]);
radioButtonGroup.add(radioButtons[i]);
radioButtons[i].addActionListener(new RadioButtonListener());
}
}
private class RadioButtonListener implements ActionListener
{
public void buttonclicked (ActionEvent e)
{
drawingPanel.repaint();
}
}
}
here is the code also for the drawingPanel class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DrawingPanel extends JApplet
{
private int timeDelay = 30;
private Timer timer;
private JRadioButton[] radioButtonArray;
public DrawingPanel(JRadioButton[] rbArray)
{
radioButtonArray = rbArray;
setBackground(Color.white);
setPreferredSize(new Dimension (300,200));
}
public void paint(Graphics g)
{
super.paint(g);
if (radioButtonArray[0].isSelected())
{
g.setColor(Color.black);
g.drawLine(10, 10, 290, 190);
}
if (radioButtonArray[1].isSelected())
{
g.setColor(Color.black);
g.drawRect(20, 20, 50, 50);
}
if (radioButtonArray[2].isSelected())
{
g.setColor(Color.black);
g.drawOval(40, 155, 75, 50);
}
if (radioButtonArray[3].isSelected())
{
g.setColor(Color.blue);
g.fillOval(200, 125, 75, 50);
}
}
}
Thanks for the help!

New Topic/Question
Reply



MultiQuote



|