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
29
votes
5 answers

Android: OnTouch, MotionEvent.ACTION_MOVE is not recognized?

Here is my code, I want to detect when my finger goes down the screen so when I touch the screen I detect the ACTION_DOWN but when I go down the screen with my finger, ACTION_MOVE is not recognized, neither ACTION_UP Do you know why? float…
morg
  • 1,173
  • 4
  • 18
  • 36
8
votes
1 answer

remove a selected row from jtable on button click

I want to remove a Selected row from a table in java. The event should be performed on button click. I will be thank full if someone helps... For example there is a table named sub_table with 3 columns i.e sub_id, sub_name,class. when I select one…
kdubey007
  • 310
  • 3
  • 4
  • 9
5
votes
1 answer

Why cant i do addMouseListener(e ->{ });?

I currently am using this code here for my mouse listener: public void mousePressed(MouseEvent e) { JLabel labelReference=(JLabel)e.getSource(); if(labelReference.getBackground()==HighLight) { turn^=true; if(turn==true){ …
5
votes
1 answer

Javafx button sending arguments to ActionEvent function

I'm learning how to use javafx, along with scenebuilder by creating a very basic calculator but I've come across a problem where it's hard for me to find a way to not have a seperate function for each button. I need to know if there's a way for a…
Foo
  • 53
  • 1
  • 1
  • 4
5
votes
4 answers

GUI not updating visually before running ActionEvent

To expound a little more, I have a GUI that looks like: Then I have an action listener on the OK button that starts like: //OK Button Action Listener private void okButtonActionPerformed(ActionEvent e) { //Enable/Disable Buttons …
Jtaylorapps
  • 5,680
  • 8
  • 40
  • 56
5
votes
1 answer

Must implement the inherited abstract method

My class implements ActionListener. I have implemented the following nested classes below: JMenuItem mntmNew = new JMenuItem("New..."); mntmNew.addActionListener(new ActionListener(){ @Override public void…
Daniel
  • 169
  • 2
  • 3
  • 9
4
votes
2 answers

How to perform multiple actions for a Button depending on ComboBox selection in JavaFX

This is the main class to create the user interface: public class Test extends Application { @Override public void start(Stage primaryStage) { FlowPane mainPane = new FlowPane(); FlowPane query = new FlowPane(); …
NSar
  • 41
  • 5
4
votes
3 answers

What does ActionEvent e mean?

I am learning Java and would really like to have a deeper understanding of what the ActionEvent e perameter means and stands for. When I code I don't just want to spit out lines that work, but I don't understand. I want to have a full understanding…
MooseMan55
  • 524
  • 2
  • 6
  • 21
3
votes
1 answer

JavaFX ComboBox setItems triggers onAction event

I have an editor in FXML and a controller which sets the domain object upon selection in a treeview. So every time a new object is selected in the treeview, the controller unbinds all controls in the editor from the previous object and binds to the…
Alex
  • 1,387
  • 2
  • 9
  • 14
3
votes
2 answers

ActionEvent get source of button JavaFX

I have about 10 buttons which are going to be sent to the same method. I want the method to identify the source. So the method knows button "done" has evoked this function. Then I can add a switch case of if statement to handle them accordingly.…
CookieMonster
  • 241
  • 1
  • 9
  • 26
3
votes
1 answer

How to call an Action from a different class in Java

How would I call an Action from another class in Java? I got a CloseTabButton class online that allows a simple close tab button on each JTabbedPane, but when the tab is closed, I would like a dialog to pop up based on information (if file is not…
Vince
  • 2,596
  • 11
  • 43
  • 76
3
votes
1 answer

Javafx - Syncronization delay - card flips

I'm actually working on a memory game and I'm stuck at the point where I should write the gameplay-part of the game. So: I have an array of N card objects. Each object has an attribute called cardNum - an identifier. I think I should write an…
Adorjan
  • 39
  • 9
2
votes
2 answers

How to retrieve string value call from existing specific JButton variable in java?

private void jButton_1ActionPerformed(java.awt.event.ActionEvent evt) { String text = ""; texto = RandomStringUtils.randomAlphanumeric(12); System.out.println(text); …
wicked
  • 43
  • 9
2
votes
1 answer

How do i test with JUnit for information inside of a void actionEvent

I am trying to get information from inside a void actionEvent so I can use it for JUnit test ( first time trying to use JUnit ). But i am not sure how to do this. If anyone can throw some guidance, i would appreciate it. Here is my code below. (this…
2
votes
1 answer

Java, change JLabel text on click

I'm new to this site and to Java programming and I'd greatly appreciate a bit of help. I'm trying to make a really simple program using SWING where the user clicks a button and a label's text changes from "Hello" to "Bonjour". These are the two…
1
2 3
20 21