Solved

Error:  Does not override abstract method actionPerformed

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 38
network + 7 80
split string containing \r\n in Java 46 38
Java SE 8u111  Lot of stuff broke 11 54
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

25 Experts available now in Live!

Get 1:1 Help Now