Button event handling in JApplet

Posted on 2005-04-05
Medium Priority
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
  • 2
LVL 15

Expert Comment

ID: 13712986
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.
LVL 15

Expert Comment

ID: 13713043
LVL 92

Accepted Solution

objects earned 375 total points
ID: 13713910
I'd suggest using an anonymous inner class to call the appropriate method:

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

840 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