954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JAVA help ACTIONLISTENERS

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.

ineedjavahelp
Newbie Poster
1 post since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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

cosi
Junior Poster
153 posts since Aug 2004
Reputation Points: 17
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You