Questions tagged [actionevent]

In Java, an action event is a semantic event which indicates occurrence of an action generated by a component like a button. This action event then passes to its ActionListener object, which is done by calling addActionListener method of the component.

When a user performs an action event like a click event on a button in any java based application this click is transformed to an ActionEvent that is generated and received by its ActionListener object. ActionListener is a java interface which works as a receiver of action events.

The class that is interested in processing an action event should necessarily implement this interface, and the object created with that class is registered with a component, using the component's addActionListener method. When the action event occurs, that object's actionPerformed method is invoked whenever an action occurs.

The class ActionEvent is a public class which extends AWTEvent class of java. The action event like clicking of a button can also be performed using keyboard by pressing the space bar.

Class ActionEvent provides 3 predefined constructors:

  • ActionEvent(Object source, int id, String command) Constructs an ActionEvent object.

  • ActionEvent(Object source, int id, String command, int modifiers) Constructs an ActionEvent object with modifier keys.

  • ActionEvent(Object source, int id, String command, long when, int modifiers) Constructs an ActionEvent object with the specified modifier keys and timestamp.

Usage: The tag actionevent can be used for programming problems related to GUI applications and event handling based problems in java. This tag should not be used for problems related to event handling in javascript and other languages.

Official documentation for class ActionEvent can be found at http://docs.oracle.com/javase/7/docs/api/java/awt/event/ActionEvent.html

306 questions
2
votes
4 answers

return a value when an JButton actionperformed event is called

I have some problem with JButton action events, I have declared a global variable (boolean tc1) and a JButton t1. When I press the JButton I need to change the value of the boolean variable to 'true'. Can any one help me out? My code goes…
ram
  • 41
  • 2
  • 2
  • 4
2
votes
2 answers

Getting the name of a JButton on click

@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == thirdBtn) { //System.out.println("Third Button Click"); System.out.println(e.getSource()+" Click"); } } In the code above, I was…
Exikle
  • 1,155
  • 2
  • 18
  • 42
1
vote
0 answers

Multiple operations at same time gives 0.0 as output.Calculator using swing

I created a calculator using Java swing.Frame creation and button arrangements were all set.I used ActionListener interface.And the program were execute successfully,when i performed a single operation along with two operands(eg:5+2). Working is…
Amalshanth
  • 29
  • 1
  • 7
1
vote
1 answer

How to Handle Events in a multiple Class Java Swing Project?

For example I have two Java Classes: public class MainFrame extend JFrame implements ActionListener{ public SouthPanel SPanel = new SouthPanel(); public int foo = 0; MainFrame() { //MainFrame config …
1
vote
0 answers

Java Is it possible to create an actionPerformed() like method but takes a different parameter?

I have to create a very basic GPS for a project. In my interface, I have an animation of a car that moves from point A to point B. The code that makes the car move is implemented in the actionPerformed(ActionEvent e) method and is working fine. But…
Filzo
  • 69
  • 7
1
vote
0 answers

Change Boolean variable into an ActionEvent Java

I have a method that generates a JPanel with one checkBox. The method has 3 parameters, one of them is a Boolean value that is null. When I use the Boolean parameter into ActionEvent, the system don't recognize it. Also, I use if look because I want…
Jeanette
  • 11
  • 1
1
vote
1 answer

Choosing between multiple action events

So let´s just say I have 3 different ActionEvents and the class ExecuteAction should execute one of these event with the given integer action. Int action could be randomly generated or be given through a text field and all actionEvents should share…
user14153199
1
vote
1 answer

Changing value of parameter within a JButton ActionEvent returns error, "must be final or effectively final"

I am trying to make a function that creates a JButton. The button either increases or decreases an R, G, or B value(red, green, blue). The user enters a few parameters, the buttons parent (JPanel) The text on the button (String) The function of the…
CodingNinja
  • 245
  • 1
  • 12
1
vote
0 answers

JFRAME, MouseListener Draw a Circle

I need your help I have to draw an ellipse (coloured) in the center of the window. On the bottom are buttons. One button "Exit", for closing the window One button "Change Color" , color changing When I click the mouse (anywhere) there have to…
1
vote
1 answer

Codename One set action event from different class for button in dialog

I have an Android application with a dialog and a few buttons inside. I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it. Creating a test class, I…
rainer
  • 3,295
  • 5
  • 34
  • 50
1
vote
1 answer

Using Enter Key instead of Left Click to fire a Button only when button.isFocused() is true

i write a javaFX program with a button named "okayButton" and every time i click on it, the program will print a message in Command Line. My main question is how to use this button also by enter only when okayButton.isFocused() returns true this…
ARiyou Jahan
  • 622
  • 6
  • 7
1
vote
2 answers

How to properly format an ActionEvent so JButtons will work

I have set up some ActionListeners, however only 'Takeoff' works. The other buttons do not work when they are clicked. When they are clicked, nothing happens. I have tried to create a new ButtonHandler, but that did not work. ButtonListener l = new…
1
vote
1 answer

Incrementing by 1 when pressing a button

My code is very long so I will only be adding snippets that are relevant. Okay so I've been trying to increment a label by one using the following code: btnComplete.setOnAction(new EventHandler() { public void…
comp1005
  • 25
  • 6
1
vote
2 answers

How to manage multiple buttons with one event handler method in Javafx and Scene Builder

I have 14 pairs of Buttons associated with two groups of textFields that increment and decrement their associated textFields by 2. Each text field displays how many pairs of plates of specific weights are to be loaded onto a barbell. They are stored…
CompEng
  • 55
  • 1
  • 8
1
vote
2 answers

Java Jframe no compilation error, but nothing appears in my JPanel

Hello I am making a project where I have to put 4 buttons using JFrame but nothing inside of my buttons are appearing and I don't understand why because I have no errors and I don't see what can cause the problem. I have to give it as a project but…
1 2
3
20 21