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

How to identify mouse release moment using ActionEvent in java

I have created DateChooser panel using DateTimeSpinner with java. Is there any posibility to identify the mouse release moment of that dateTimeSpinner using ActioEvent?
1
vote
3 answers

Call actionPerformed of a JTextField using its object

I have a javax.swing.JTextField named SearchBox with an actionPerformed Event. public void SearchBoxActionPerformed(java.awt.event.ActionEvent evt){ //TODO } What I want to do is to call the above method from another method in a different…
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
1
vote
1 answer

Conditional EventHandler

Can I make anonymous event handler method to act conditional like JButton activeDataBtn = new JButton("Active"); activeDataBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if…
Ashford Tulgaa
  • 27
  • 2
  • 13
1
vote
0 answers

JavaFx controller not opening web browser

I am taking my first step with JavaFx, using InteliJ for debugging and construction of the scene. I have added a button that is supposed to open the standard web browser. To check the link between the button and the controller, I have added a…
rainer
  • 3,295
  • 5
  • 34
  • 50
1
vote
2 answers

JTable + JPopupMenu + ActionListener = Nightmare

My main class is a window containing graphical components including a JTable. I have created a public class ContextMenu which is a custom implementation of a JPopupMenu and containing multiple JMenuItem. I have registered a mouseListener on my…
aress31
  • 340
  • 5
  • 20
1
vote
1 answer

setLocation in actionPerformed change button location only if there are no integer incrementation

import javax.swing.*; import java.awt.event.*; public class SimpleGUI3 implements ActionListener { JButton button; private int numClick; public static void main(String[] args) { SimpleGUI3 gui = new SimpleGUI3(); …
jakarjakar
  • 33
  • 6
1
vote
2 answers

How to call variables from another class into an ActionListener method?

I would like to apologize in advance I am new to java and don't know very much so stick with me please. I would like to know how to get my character attributes from one ActionListener method in one class to another ActionListener method in another…
kdl
  • 55
  • 6
1
vote
0 answers

How a Button can have more than one mouse click ActionEvent, then place data into objects, then places objects into List and display List in console?

I've created a stage and scene application for java. This program asks the user to click a button that says customer info. Then a dialog pops up in the application window and has Labels and TextFields for customer info. Then user clicks ok and it…
1
vote
2 answers

reading when a button is pressed java

i cannot figure out how to get my code to tell when the button is pressed. i was taught poorly, just FYI so any help will need to be greatly detailed. also, i am new to the site so if the post isnt formatted correctly i am sorry. public static void…
1
vote
1 answer

JavaFX Assigning action to all buttons in an array of arrays using for-loop

We have this warm up exercise where we're supposed to create this reallllly simple game which's UI is pretty much set up . I got the error "Local variable i defined in an enclosing scope must be final or effectively final". I didn't understand it,…
Duc Nguyen
  • 165
  • 1
  • 5
1
vote
0 answers

graph stream mouse button clicks wont work

I am using graphstream with my swing application causing a lot of problem... public class Clicks implements ViewerListener{ protected boolean loop = true; public Clicks() { Graph graph = new SingleGraph("Clicks"); graph.addNode("A"); …
1
vote
1 answer

Is there a way to halt a method until a button is pressed?

I have been coding for a card game and cannot get my method to wait for a button to be pressed. The general code goes like this. When I run the code, doTask() has a segment where it needs to wait for a button to be pressed. However, the method does…
user2999870
  • 345
  • 4
  • 12
1
vote
1 answer

Using TextFields in Two Methods without Declaring Universally

Hi i am new to Using JFrame & Action Listener, I want to get input from more than 20 fields and then I need to store it in a database. I Perform those storing operation in an ActionEvent Class Dialog_Box { JTextField Name; //1st TextField …
Yuvi
  • 41
  • 1
  • 9
1
vote
0 answers

ActionEvent for query result - Java

I would like to know the result of a query performed in a popup that extend to windowPane. Here is my class that open the window: private void processBtnChangeRateAction(ActionEvent e) { AccountChangeRate win = new…
Marc El Bichon
  • 397
  • 1
  • 7
  • 24
1
vote
0 answers

Why is Action Listener malfunctioning?

I am developing a basic Tic Tac Toe game using Java. It is supposed to have 9 buttons in a grid, and when you click one, X appears. Once you've clicked on a button, a kind of switch variable i should change value, so the next time you click O…