Hi, just a question on basic Java Swing. I have tried messing around with it and the part where I add the ActionListener, Eclipse isn't happy. It gives the following message: The type JFrameMessing must implement the inherited abstract method
ActionListener.actionPerformed(ActionEvent)
Does anyone know what's wrong?
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class JFrameMessing extends JFrame implements ActionListener {
/**
* "Added to keep Eclipse happy"
*/
private static final long serialVersionUID = -4466031902376712922L;
public JFrameMessing(){
Toolkit tools = getToolkit();
Dimension screenSize = tools.getScreenSize();
int centerX = screenSize.width/2-getWidth();
int centerY = screenSize.height/2-getHeight();
//System.out.println("x is " + centerX + " and y is " + centerY);
JFrame theFrame = new JFrame("My first test frame !");
setLayout(new FlowLayout());
setSize(300, 300);
setLocation(centerX, centerY);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//button
JButton closeButton = new JButton("close !");
ActionListener closeAL = new ActionListener(){
public void actionPerformed(ActionEvent theEvent){
System.exit(0);
}
};
closeButton.addActionListener(closeAL);
}
public static void main(String[] args) {
JFrameMessing newFrame = new JFrameMessing();
newFrame.setVisible(true);
}
}
ActionListener.actionPerformed(ActionEvent)
Does anyone know what's wrong?
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class JFrameMessing extends JFrame implements ActionListener {
/**
* "Added to keep Eclipse happy"
*/
private static final long serialVersionUID = -4466031902376712922L;
public JFrameMessing(){
Toolkit tools = getToolkit();
Dimension screenSize = tools.getScreenSize();
int centerX = screenSize.width/2-getWidth();
int centerY = screenSize.height/2-getHeight();
//System.out.println("x is " + centerX + " and y is " + centerY);
JFrame theFrame = new JFrame("My first test frame !");
setLayout(new FlowLayout());
setSize(300, 300);
setLocation(centerX, centerY);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//button
JButton closeButton = new JButton("close !");
ActionListener closeAL = new ActionListener(){
public void actionPerformed(ActionEvent theEvent){
System.exit(0);
}
};
closeButton.addActionListener(closeAL);
}
public static void main(String[] args) {
JFrameMessing newFrame = new JFrameMessing();
newFrame.setVisible(true);
}
}