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?
Printable View
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?
add the actionListener to the button:
then override the actionPerformed method:Code:
ButtonName.addActionListener(this);
Code:public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == ButtonName)
{
//Do something
}
}
Code:import java.awt.event.*;
import java.applet.Applet;
class MyApplet extends Applet implements ActionListener{
public void actionPerformed(ActionEvent evt){}
}
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.
Oh, so all I had to do to override it was to change the variable name?
perhaps you can show us your code? :D
No need, System_Error had the answer, I was just wondering. Thanks.