Solved

Error:  Does not override abstract method actionPerformed

Posted on 2007-04-04
3
1,353 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

810 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