Solved

Error:  Does not override abstract method actionPerformed

Posted on 2007-04-04
3
1,344 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:mayankeagle
mayankeagle 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now