Solved

Error:  Does not override abstract method actionPerformed

Posted on 2007-04-04
3
1,367 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 40 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 45 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 40 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

726 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