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
votes
3 answers

label outside the actionPerformed does not refresh

I tried to implement this code that basically what it does is when I press the only button it has, it increments one unit in the label above the button. In other words, it shows how many times has the user pressed the button. But My problem is that…
-1
votes
1 answer

Java event handler String error

I am trying to make a GUI application where I am using 2-D array registered with an ActionListener. At compile time I am getting a String s = ((Button)o).getLabel(); declaration not valid here. error. In my application if you click the button every…
-1
votes
2 answers

Java: actionPerformed throws exceptions and refuses to work

I am working on a program that takes a txt file which is a list of movies and selects a random movie from it. Everything is working normally but there is a GUI problem. I can't make a JLabel change text to that selected movie when I press a…
pandasticus
  • 33
  • 2
  • 4
-1
votes
2 answers

checking if a jbutton is clicked in another java file

good day everyone. I have many java files in a project in netbeans. One file is named mainFile while some are addSale, addAttendance. In my mainFile.java, I created an actionPerformed method to check if a button is clicked. But the buttons that I…
Rocky
  • 429
  • 1
  • 9
  • 26
-1
votes
2 answers

Java - Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

My complete code will compile but when I run it I get the errors below stating with the NullPointerException. I have also included the section of code that the error refers to but I have no idea how to make the linked list not have a null when this…
-1
votes
2 answers

JVM does not respond when user clicks button 1/2, it just becomes stuck

I am trying to make a program that user is able to enter a date like: 28 -03 - 2014. This and the program reads that, gives the date of tomorrow like: 29 - march - 2014. The program must check about: String max 10. date of day(2 digit): 1 -…
-1
votes
2 answers

DropListener that retrieves X & Y from JButton[X][Y] after a Drag and Drop onto JButton[][] Grid

I am creating a battleship game inside a GUI using Java Swing. For now I am just trying to get this grid working so that a user may drag and drop the battleship from the bottom of the grid onto a spot within the grid above. I would like to save the…
Kyle Bridenstine
  • 6,055
  • 11
  • 62
  • 100
-1
votes
1 answer

java passing parameters into action event methods

I'm not sure how to pass parameters/arguments into action events. This program is supposed to generate a random times table "flash card", compare it to the correct answer and return output to the console letting the user know if their input was…
Michael Queue
  • 1,340
  • 3
  • 23
  • 38
-1
votes
2 answers

Using KeyListener for a Calculator in NetBeans

I have written a calculator in NetBeans and it functions perfectly. However, I have to actually click the buttons to insert numbers and am trying to remedy that with a KeyListener. I have all my numbers and function buttons set inside a JPanel named…
Nick
  • 1
  • 1
  • 3
-1
votes
1 answer

Adding handler to button presses

I have many GUI forms with many buttons on each GUI form. I am wanting to detect when a user clicks on any of these buttons. My question is this: Should I add code individually to each button, or can I cater to each button press by a public method…
user2351151
  • 725
  • 4
  • 12
  • 16
-1
votes
1 answer

ActionEvent "Cannot Find Symbol"

I am making a program to wrap text, by words or by characters, depending on user input. I have everything working, except for my ActionEvent that's giving me a "Cannot Find Symbol" error. I'm sure it's something small that I've missed, but I can't…
Acitropy
  • 113
  • 1
  • 5
  • 18
-2
votes
1 answer

JavaFX: Help setting event listeners to set variables and print text?

I am writing a program that is a "sandwich ordering app". Think subway. Bread choice, meat choice, cheese choice, etc. I'm trying to use each type of element (radio buttons, combobox, slider, listview, checkbox, and textfield). I am having trouble…
torireb
  • 1
  • 2
-2
votes
2 answers

Finding the 3 most common elements in an array

My code is pretty long but I will include the relevant snippet. I am creating a GUI with elements of a store. I have a textfield called popularItemsTxt that contains the 3 most popular items of my list. for(int i =0; i<3;i++) { …
coding101
  • 27
  • 5
-2
votes
1 answer

Calling an arrayList from another class which is private

I am trying to display an arraylist in a gui. However I am getting some troubles. I need to check if my game is legal, if it is not legal then it calls getProblems which displays the arraylist. I tried to call getProblems directly in the GUI class…
-2
votes
1 answer

Tic Tac Toe game in Java

Ok guys...I'm stumped again. I managed to get the game working. However, now I'm down to the point of trying to code the win conditions. I'm thinking of using a boolean array for each of the buttons, but can't figure out how to cross reference the…
1 2 3
20
21