?
Solved

Error:  Does not override abstract method actionPerformed

Posted on 2007-04-04
3
Medium Priority
?
1,394 Views
Last Modified: 2013-11-24
I keep getting the following error:


ParkingMeterGUI2.java:13: proj3.ParkingMeterGUI2 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
class ParkingMeterGUI2 extends JPanel implements ActionListener
^


Can someone kindly point me in the right direction?


class ParkingMeterGUI2 extends JPanel implements ActionListener
{    
   private JFrame parkingMeterWindow;
   private static final int WINDOW_WIDTH = 995;
     private static final int WINDOW_HEIGHT = 1000;
         
   private String title;
   private String anotherTitle;
     
   private JLabel label;
     
   private JButton quarterButton = new JButton( "25" );
   private JButton dimeButton = new JButton( "10" );
   private JButton nickelButton = new JButton( "5" );
   private JButton pennyButton = new JButton( "1" );
     
   //-------------------------------------------------------------
   public ParkingMeterGUI2( String windowName, int width, int height )
   {
      initialize( );
  }
     
   //-------------------------------------------------------------
   public void initialize( )
   {    
      // create the frame
      //window = new JFrame( windowName );
      parkingMeterWindow = new JFrame( "Parking Meter" );
      parkingMeterWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      parkingMeterWindow.setBackground( Color.WHITE );
      parkingMeterWindow.getContentPane( ).add( this );
      parkingMeterWindow.setSize( WINDOW_WIDTH, WINDOW_HEIGHT );
         
      // create label (label replaces drawString)
      label = new JLabel( title, SwingConstants.CENTER );
      add( label );
         
      setLayout( new BorderLayout( ) );
      add( new JLabel( anotherTitle, SwingConstants.CENTER ), BorderLayout.NORTH );
     
      /*
      The most common JPanel constructor has no parameters.
      This creates a panel with the default layout (FlowLayout).
      Call setLayout() to change the layout.
     
      JPanel p = new JPanel();
      p.setLayout(new FlowLayout());
      You can optionally specify the layout in the JPanel constructor call.
      JPanel p = new JPanel(new FlowLayout());
      */
     
     
      JPanel buttonPanel = new JPanel( );
      add( buttonPanel, BorderLayout.NORTH );
         
         
      //quarterButton.addActionListener( this );
      quarterButton.addActionListener( new ActionListener( )
      {
         public void actionPerformed( ActionEvent e )
         {
            //numberOfQuarters++;  
            setBackground( Color.GREEN );    
         }
      } );
     
      //dimeButton.addActionListener( this );
      dimeButton.addActionListener( new ActionListener( )
      {
         public void actionPerformed( ActionEvent e )
         {
            //numberOfDimes++;
            this.setBackground( Color.BLUE );  
               
         }
      } );
     
      //nickelButton.addActionListener( this );
      nickelButton.addActionListener( new ActionListener( )
      {
         public void actionPerformed( ActionEvent e )
         {
           //numberOfNickels++;    
            this.setBackground( Color.RED );
         }
      } );
     
      //pennyButton.addActionListener( this );
      pennyButton.addActionListener( new ActionListener( )
      {
         public void actionPerformed( ActionEvent e )
         {
            //numberOfPennies++;
            this.setBackground( Color.YELLOW );
         }
      } );  
0
Comment
Question by:CharleneS77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 160 total points
ID: 18855707
>>class ParkingMeterGUI2 extends JPanel implements ActionListener

replace the above with

class ParkingMeterGUI2 extends JPanel
0
 
LVL 3

Accepted Solution

by:
cavey_79 earned 180 total points
ID: 18857728
You either need to implement the method specified in ActionLister or remove it like ksivananth said. Looking at the code, I think initially you wanted to use this class as an action listener:
 //quarterButton.addActionListener( this );
      quarterButton.addActionListener( new ActionListener( )
      {
         public void actionPerformed( ActionEvent e )
         {
            //numberOfQuarters++;  
            setBackground( Color.GREEN );    
         }
      } );

But that line is commented out so it's safe to remove the "implements ActionListener" part, just as suggested above.
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 160 total points
ID: 18860921
Or else if you don't want the anonymous inner class, then you can add an actionPerformed () method with the same code, to your ParkingMeterGUI2 class and un-comment the statement: >> //quarterButton.addActionListener( this );
(remove the current anonymous action listener too, in that case)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question