GUI error: is not abstract and does not override abstract method
:confused:
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:
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);
}
}
Code :
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:
Code :
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) :
Code :
private class ButtonListener implements ActionListener {
In which ButtonListener is red underlined
Any input appreciated
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:
Quote:
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
Re: GUI error: is not abstract and does not override abstract method
the method actionperformed should be
Code Java:
public void actionPerformed(ActionEvent event)
{
//Code not included
}
Simple typo.
Re: GUI error: is not abstract and does not override abstract method