Button event handling in JApplet

Posted on 2005-04-05
Last Modified: 2012-05-05
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.
Question by:ViceroyFizzlebottom
    LVL 15

    Expert Comment

    Have a look at:
    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.
    LVL 15

    Expert Comment

    LVL 92

    Accepted Solution

    I'd suggest using an anonymous inner class to call the appropriate method:

    button.addActionListener(new ActionListener()
       public void actionPerformed(ActionEvent event)

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now