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
0 answers

JavaFX, JasperReports and JRDataSource

I am working in this aplication in order to generate reports with JRDataSource interface. I think I am doing ok, but obviusly I'm missing something. I am trying to do a GUI where i can introduce 4 parameters, save them by catching an event (button…
Lal
  • 21
  • 4
2
votes
1 answer

Debugging my Button

This is my JPanels class for a small program I am working on. The program launches and displays my GUI correctly. Issue is for some reason my actionEvent isnt firing onClick. I put in a println in the actionPerformed to see if it was actually…
Staver
  • 63
  • 8
2
votes
2 answers

Codename one - Navigate from Form A to Form B with action events and new GUI builder - and navigate back from B to A

What is the best practice with the new GUI Builder, to simply navigate from "form A" to another "form B" by clicking a button in "form A", with use of the action events? If I create Form B inside Form A like this public void…
socona
  • 432
  • 3
  • 13
2
votes
3 answers

How to connect multiple buttons in a storyboard to a single action, by code not drag&drop?

I'm currently using Xcode 7.3 and I'm simply wondering how to select multiple buttons across different UIViews, but under a single view controller. CMD clicking doesn't seem to work. I need this functionality because in Xcode 7.3 the only way to let…
2
votes
1 answer

Assigning an action to each button, in an array of buttons in JavaFX

I've created an array of ComboBoxes and an array of buttons in JavaFX. I'd like to assign each button of the array, to do something to the ComboBox of the corresponding index: for(int i = 0; i < 6; i++) { colorBox[i] = new ComboBox(); …
Niels Heltner
  • 33
  • 1
  • 5
2
votes
1 answer

ActionEvent not recognizing CTRL keybinding

I'm trying to integrate keybindings into a program I'm making, but as that program is long, I'm trying to learn on a smaller similarly coded program that I found on StackOverflow. Here's the code I'm using: import java.awt.Color; import…
2
votes
1 answer

Moving ball inside rectangle program

I am creating a moving ball program that features a ball moving and bouncing off the walls of a rectangle with go and stop buttons at the bottom. What I am having problems with is I want the ball to start off moving when the program is run and…
David
  • 23
  • 4
2
votes
2 answers

Stopping Timer from another class

Basically this code gets called from a JButton(in another class) to move the cube by repainting it over and over again. I wish to create another JButton to stop the timer (timer.stop()) from another method. How would i do that private ActionListener…
user3249265
  • 113
  • 1
  • 5
  • 16
2
votes
1 answer

ActionEvent and MouseEvent right-click JAVA Mac

I'm not sure if this a Mac issue, or an issue with my code. I am creating a grid of buttons. For each button I use ActionEvent for a regular click, and MouseEvent for a right click. What happens is when I CTRL-click the mouse event performs fine,…
Michael Ramos
  • 5,523
  • 8
  • 36
  • 51
2
votes
2 answers

Can you call an action event in java without an action

I was wondering if you can have an action event in java occur when no action has taken place. What I mean is tricking it into thinking an action has occured when it has not and then running an action event. The reason I ask this is because it would…
Cameron Roberson
  • 111
  • 4
  • 20
2
votes
1 answer

Dealing with LOTS of Key mappings

What is the best way to define the actions for lots of key mappings for a component in Swing? I built my own Text View in Swing and want to define actions for a lot of keys. The way I'm currently doing it (for around 10 keys so far) is: ActionMap…
alistair
  • 1,164
  • 10
  • 27
2
votes
1 answer

Event call doesn't work with key bind or click - what's the logical error?

I'm trying to call this event below; I create the frame with TabBuilder (since is part of my application) then it calls the Search screen which is popping up; but the event of the search with key bind or simple click on the button is not working and…
Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77
2
votes
1 answer

How to implement an actionListener for space bar as action event

I have this set up to update pretty constantly on the timer, but I want to be able to pause the timer with the spacebar. I have attempted to implement an actionListener, but I am not sure what to apply it to. Most of the examples I can find relate…
Peter F
  • 435
  • 1
  • 8
  • 17
2
votes
1 answer

adding listeners to JButton array;

I have the following code which creates a JButton array on button click. Ope[] is publically declared in class. I have problem that I got null pointer. That is it doesn't print 2nd in loop ie. doesn't go in inner iteration. Please tell me how to…
vibhor
  • 59
  • 2
  • 7
2
votes
1 answer

how to prevent running same JInternalFrame more than once

How can you prevent the JInternalFrame not to open more once, currently in my application it opens many times. Also how can I make my application run only if there is not the same application running. This is the code for JInternalFrame private…
mohamed nur
  • 331
  • 1
  • 15
1
2
3
20 21