6 Replies - 1322 Views - Last Post: 15 April 2011 - 09:34 PM Rate Topic: -----

#1 rowsdower  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 14-April 11

class is not abstract and does not override abstract preform

Posted 14 April 2011 - 08:32 PM

Hey guys, how's it going?

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!

Is This A Good Question/Topic? 0
  • +

Replies To: class is not abstract and does not override abstract preform

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: class is not abstract and does not override abstract preform

Posted 14 April 2011 - 08:37 PM

	
	  private class RadioButtonListener implements ActionListener
	 
	{
		public void buttonclicked (ActionEvent e)
		{
			drawingPanel.repaint();
		}
	}


A class that implements ActionListener should implement
public void actionPerformed(ActionEvent e)

It can have a buttonclicked() thow but this is your implementation
Was This Post Helpful? 1
  • +
  • -

#3 rowsdower  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 14-April 11

Re: class is not abstract and does not override abstract preform

Posted 14 April 2011 - 09:32 PM

Thanks for the response!

Changed the buttonclicked to actionPerformed and it complied without errors.

However, none of my radio buttons are showing up, any idea why?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: class is not abstract and does not override abstract preform

Posted 14 April 2011 - 09:39 PM

And Applet should have an init method where you will:
- init your JRadioButton array
- init each of them
- add them tou jour applet

something like

public void init() {
   radioButtons = new JRadioButtons[titles.length];
   for(int i = 0; i < radioButtons.length) {
      radioButtons[i] = new JRadioButton(titles[i]);
      add(radioButtons[i]);
   }


Was This Post Helpful? 1
  • +
  • -

#5 rowsdower  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 14-April 11

Re: class is not abstract and does not override abstract preform

Posted 14 April 2011 - 10:05 PM

Whoops, i forgot the add(radioButtons[i]) bit to the code, so the method buildRadioPanel now looks like this:

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());
			add(radioButtons[i]);
			
		}
	}



Still nothing showing up. The method is being called in the init method so that doesn't seem to be the issue. Any other ideas?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: class is not abstract and does not override abstract preform

Posted 15 April 2011 - 03:53 AM

add(radioButtons[i]);
should be
radioPanel. add(radioButtons[i]);

and after the for() loop you have to add(radioPanel); to add the newly created radioPanel to your Applet
Was This Post Helpful? 1
  • +
  • -

#7 rowsdower  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 14-April 11

Re: class is not abstract and does not override abstract preform

Posted 15 April 2011 - 09:34 PM

Thanks for all your help pbl, that did the trick!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1