Click to See Complete Forum and Search --> : ActionListeners
Nove
Jun 17th, 2005, 03:16 PM
I need to respond to a press on a JButton in a JApplet. I've tried adding implements actionlistener but I get the "Class is not abstract" error. How do you implement an actionlistener in a JApplet?
System_Error
Jun 17th, 2005, 03:48 PM
add the actionListener to the button:
ButtonName.addActionListener(this);
then override the actionPerformed method:
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == ButtonName)
{
//Do something
}
}
Dillinger4
Jun 17th, 2005, 06:05 PM
import java.awt.event.*;
import java.applet.Applet;
class MyApplet extends Applet implements ActionListener{
public void actionPerformed(ActionEvent evt){}
}
Dillinger4
Jun 17th, 2005, 06:20 PM
The reason why you get that MyApplet is not abstract and does not overide abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener is simply that you must either override all abstract methods from the interface or declare your class abstract.
Nove
Jun 17th, 2005, 07:47 PM
Oh, so all I had to do to override it was to change the variable name?
oceanebelle
Jun 18th, 2005, 12:33 AM
perhaps you can show us your code? :D
Nove
Jun 18th, 2005, 11:07 AM
No need, System_Error had the answer, I was just wondering. Thanks.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.