I just got to the swing section in a java book but am having some trouble compiling a sample of code. I keep on getting this error whenever I use java.awt.event:
Code:
Push_Exit.ClickListener is not abstract and does not override abstract method actionPreformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
Any help? Here's a sample code piece I just made:
Code:
import javax.swing.*;
import java.awt.event.*;
public class PushExit extends JFrame
{
public static void main(String[] args) {new PushExit();}
private JButton mybutton;
public PushExit()
{
this.setSize(200,75);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setTitle("I am a JFrame.");
JPanel mypanel=new JPanel();
mybutton=new JButton("And I am his JButton.");
ClickListener bl=new ClickListener();
mybutton.addActionListener(bl);
mypanel.add(mybutton);
this.add(mypanel);
this.setVisible(true);
}
private class ClickListener implements ActionListener
{
private int clickcount=0;
public void actionPreformed(ActionEvent e)
{
if(e.getSource()==mybutton)
{
if(clickcount==0)
{
JOptionPane.showMessageDialog(PushExit.this,
"Click me again to exit.",
"Howdy",
JOptionPane.INFORMATION_MESSAGE);
clickcount=1;
}
else
{
System.exit(0);
}
}
}
}
}