-
ActionListener Error
Hi, every time I try to compile the code below I get the following error: "addActionListener(java.awt.event.ActionListen er) in javax.swing.AbstractBunnon cannot be applied to (Start)"
Can Anyone help me?
Thanks in advance.
Code:
public class Start extends JFrame{
public static void main(String[] args) {
new Start();
}
public Start() {
JFrame f = new JFrame("Menu");
f.setSize(500, 500);
Container content = f.getContentPane();
content.setBackground(Color.blue);
content.setLayout(new FlowLayout());
JButton button1 = new JButton("Nieuw Spel"); //knop 1
content.add(button1);
f.setVisible(true);
button1.setToolTipText("blablabla");
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == button1){ //EVENT BUTTON 1 NOT NIET IN ORDE
}
}
}
-
When you use addActionListener() you have to use an argument that is an instance of the the ActionListener interface. Your Start does not implement ActionListener unless you explicitly say so:
Code:
public class Start extends JFrame implements ActionListener {