Button event handling in JApplet

Hey there. I have an applet that has some input textboxes and two buttons.
The general format is this:
public class Install extends JApplet implements ActionListener

Anyway, I'm having a hard time figuring out how to handle the button clicks as far as how to implement the
actionPerformed() method. Where should the actionPerformed method be defined and what is the best way
to handle the two button events?
Any help is appreciated.
Who is Participating?
objectsConnect With a Mentor Commented:
I'd suggest using an anonymous inner class to call the appropriate method:

button.addActionListener(new ActionListener()
   public void actionPerformed(ActionEvent event)
Have a look at: http://javaalmanac.com/egs/javax.swing/combobox_CbActionEvt.html
This sample code is for JComboBox but the same style of getting / handling the event can applied on JButton.
Basically you need to call addActionListener(actionListener) on each one of your JButton and pass an ActionListener
that will handle the event.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.