Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: GUI error: is not abstract and does not override abstract method

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default GUI error: is not abstract and does not override abstract method



    Im trying to get a simple GUI working.

    Firstly here is a brief description of the program:
    Its just a small JFrame, with 1 button and an actionListener for when the button is pressed. The number of 'pushes' is updated and printed when the button is pressed.

    I have a main class: PushCounter and another class: PushCounterPanel for which all the classes and methods are written for the JFrame

    Heres the code:

    package Chapter4;
     
    // demonstrates a GUI and an event listener
    import javax.swing.JFrame;
     
    public class PushCounter {
     
        // creates the main program frame
        public static void main(String[] args) {
     
            JFrame frame = new JFrame("Push Counter");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            frame.getContentPane().add(new PushCounterPanel());
            frame.pack();
            frame.setVisible(true);
     
        }
    }

    package Chapter4;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    // demonstrates a GUI and an event listener
    public class PushCounterPanel extends JPanel {
     
        private int count;
        private JButton push;
        private JLabel label;
     
        // constructor: sets up the GUI
     
        public PushCounterPanel() {
            count = 0;
     
            push = new JButton("Push me!");
            push.addActionListener(new ButtonListener());
     
            label = new JLabel("Pushes: " + count);
     
            add(push);
            add(label);
     
            setPreferredSize(new Dimension(300, 40));
            setBackground(Color.cyan);
        }
     
        // represents a listener for button push (action) events
     
        private class ButtonListener implements ActionListener {
     
            // updates the counter and label when the button is pushed:
     
            public void actionperformed(ActionEvent event) {
                count++;
                label.setText("Pushes: " + count);
            }
        }
    }


    And the error:

    PushCounterPanel.ButtonListener is not abstract and does not override abstract method
    action performed (java.awt.ActionEvent) in java.awt.event.ActionListener

    Its on line 33 (this line) :

    private class ButtonListener implements ActionListener {

    In which ButtonListener is red underlined



    Any input appreciated


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: GUI error: is not abstract and does not override abstract method

    Should have posted this aswell: its what i get when i actually try to run it:

    run:
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at Chapter4.PushCounter.main(PushCounter.java:14)
    Caused by: java.lang.RuntimeException: Uncompilable source code - Chapter4.PushCounterPanel.ButtonListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    at Chapter4.PushCounterPanel.<clinit>(PushCounterPane l.java:33)
    ... 1 more
    Java Result: 1

  3. #3
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: GUI error: is not abstract and does not override abstract method

    the method actionperformed should be
      public void actionPerformed(ActionEvent event) 
      {
         //Code not included
      }
    Simple typo.

  4. #4
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: GUI error: is not abstract and does not override abstract method

    Oh yeah.

    Thanks

Similar Threads

  1. Abstract
    By mamawia in forum Java Theory & Questions
    Replies: 2
    Last Post: September 3rd, 2011, 07:16 AM
  2. override list add method?
    By ober0330 in forum Collections and Generics
    Replies: 10
    Last Post: July 17th, 2011, 07:34 PM
  3. How to remove argument from abstract method.
    By jainshasha in forum Object Oriented Programming
    Replies: 12
    Last Post: June 30th, 2011, 10:33 PM
  4. Replies: 2
    Last Post: February 28th, 2011, 10:51 AM
  5. Override class method
    By mekie in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 07:06 PM