Why do I get this error?

GUI3.java:13: GUI3 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class GUI3 extends JFrame implements ActionListener
^
1 error


please help me! thanks.

Hi,

You need to have the function

public void actionPerformed(ActionEvent e) {

}

in any classes that implement ActionListener. Basically this function is called when something happens to the gui objects it is listening to. So typically you do something like this:

button.addActionListner(this);
...
...


public void actionPerformed(ActionEvent e) {

   if (e.getSource() == button) {
       // button was pressed. take action if needed.
   }
}

For a more thorough explanation, see Sun's excellent "How to Write an Action Listener" http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

Hope this helps!


Ed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.