Questions tagged [actionlistener]
Java ActionListener is an invisible GUI object that gets its method called when the user performs a certain action. Common actions include pressing the push button, toggling the toggle button, checking the checkbox, selecting an item in combo box and the like.
3,504
questions
0
votes
0
answers
32
views
JButtons don't respond to commands [closed]
package boundary;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.Border;
public class AutenticazionePanel ...
0
votes
1
answer
39
views
How to make a queue with ActionListener
Have a problem making battleship game.
I created 2 panels with game decks for player and opponent.
enter image description here
When i click on opponents tile and miss i want programm to choose random ...
1
vote
1
answer
33
views
Java Jtable Not Updating External Values
Im coding this math progam where the user buys and sells stocks and the table calculates the valuation based on price and amount of stocks the user has. (valuation = price*amt)
I used a dropdown box ...
0
votes
0
answers
10
views
Main class doesnt detect the change of an attribute [duplicate]
I have a GameEngine class that waits for the UserInterface class to change its aField attributes.
While it is null, it stays in the while loop, but whenever aField changes processCommand() is supposed ...
-2
votes
1
answer
41
views
Why are my JButtons not responding when clicked? [closed]
I'm trying to use the actionPerformed method to print a message to the corresponding buttons (in this case b1/b2/b3). I have no idea where exactly in the code the issue lies.
import java.awt.event....
0
votes
1
answer
34
views
Arraylist turns empty when having contact with listener
Hello I am writing a program for school and I am stuck on this problem where I try to get an arraylist from another class using a button, but when the arraylist comes in contact with the listener it ...
0
votes
0
answers
25
views
Problem with ActionListener to give a buttona value
I'm trying to give a functions to an array of jbuttons with ActionListener
but when I pass 'i' as variable it gives erorr :
App.java:45: error: local variables referenced from an inner class must be ...
0
votes
1
answer
53
views
Button activating automatically?
I have a button that on a gui that supposed to open a new gui and close the old one but as soon as I run the code it automatically opens the new gui without closing the old one. I also have a button ...
-2
votes
1
answer
44
views
Utilize a ActionListener object from a separate JFrame class to main class
I am building a GUI program in which specific code takes place when a certain condition is meant (JButton is pressed). I have a seperate class that constructs my Jframe called "MyFrame" .
...
-1
votes
1
answer
50
views
Neither ActionListener nor MouseListener added to JButton works for setting color in PaintComponent in JPanel
I am creating a Java program to simulate Microsoft Paint in Windows 95. There is a color palette in the bottom. Clicking any color in the palette will change the color of the painting tool like pencil....
0
votes
0
answers
25
views
Make a check for a color change button
So basicly i got a project ongoing and i need some help. It is a game where you have 25 rounded buttons that when pressed change color. So and i colored the buttons around the button pressed (max. 4) ...
0
votes
1
answer
34
views
Use value out of ActionListener in Java
I am juste starting to code, and I am trying to write a program were I would need a button to change a value (alea) that would be used out of actionPerformed methode. What I have currently wrote goes ...
0
votes
2
answers
24
views
ActionListener not implemented
I was learning about JRadiobuttons and I made three JRadioButtons in this particular program. The JRadioButtons were pizzaButton, burgerButton and hotdogButton. I wanted to print specific lines when ...
0
votes
0
answers
23
views
Java GUI - Why do values under actionPerformed method not show in other class?
A char variable was added under the .isSelected() method and it stores either 'A' or 'B'. It successfully printed "got A" and the correct value within the frame class.
But when I use the ...
0
votes
1
answer
50
views
JSF multiple actionListeners called in order with update
Using JSF 2 I understand I can call multiple actionListeners as such:
<h:commandButton value="Action">
<f:actionListener binding="#{myBean.actionOne()}" />
<...
0
votes
1
answer
23
views
Need some advice with my ActionListener in Java
I'm currently working on a program in Java(beginner) and I need some assistance getting my buttons to actually work in the GUI. I copied my code to the bottom of the post. I've written my ActionEvents ...
0
votes
1
answer
34
views
How can I increase the value in the text field with JButton?
I have a school project and I want to do an online shopping cart with Java. It has a frame, 4 different types of clothing with JLabels, one text field that displays 0 in the starting for each of them ...
0
votes
0
answers
12
views
JOptionPane: Dialog Message box not opening in java
I was trying to create a starting-level GUI in java. The GUI is simple I have three buttons, and when I click on any of them it should show a message box saying button X was clicked. But unfortunately,...
0
votes
1
answer
39
views
My ball doesn't bounce off the edge of screen when I up it's speed in java
I made a simple project in java where the ball bounces off the edges of the screen. When I changed the speed of the ball, it went through the edge of the screen. The speed of the ball are in the ...
-4
votes
1
answer
59
views
How can I stop timer and terminate program when result and userEntry are the same number?
This is the class to generate a random number
The problem i have is whenever the random number and the user entry are the same I want the timer to stop, display the you won message and terminate the ...
0
votes
0
answers
10
views
Can't add different bottons in a single actionlistener using the windowbuilder in eclipse
I made a program using the window builder (with eclipse), but with which I can't add all the buttons in a single actionlistener and actionperformed ... I tried to add "implements ActionListener&...
-1
votes
3
answers
90
views
How can I use the "+" or "-" button to make the calcul and then the "=" to display it?
I'm trying to do a basic calculator. At first I only had two buttons "+" and "-", when i pressed one of the two buttons the text is displayed. For the next step, i want to display ...
0
votes
1
answer
81
views
Inputting data to JTextField by pressing JButton
I wrote a program that creates a sudoku board according to the difficulty level chosen by the user. There's a basic GUI using JFrame and JPanel.
The board itself is built using a 2D array of ...
0
votes
0
answers
46
views
How to change an icon of a JToggleButton 2D array when clicked once?
I am trying to create a small tic tac toe game using a 2D array of JToggleButtons, I got the general layout and have a 3x3 grid of JToggleButtons and added an ActionListener to each button when they ...
0
votes
1
answer
28
views
action performed java dont run?
Good morning, I'm a bit new to java, I'm trying to create a dynamically loaded graphical application, the application has a frame with a panel that changes depending on which button is pressed, the ...
0
votes
0
answers
12
views
KeyListener in Arcanoid
even while trying to solve this problem I read that a much better solution would be to use Key Bindings. Funnily enough, I did try it and it also didn't work so I am now certain there must be a puzzle ...
0
votes
1
answer
48
views
How to update 2D rectangle drawing in the respective JPanel
I am running into an issue where I have a working code that is able to display a rectangle in a Jpanel drawpanel given input parameters from Jtextfields. However when trying to create a new rectangle, ...
-1
votes
2
answers
68
views
Where to put action listeners?
I'm a little confused about where the best class is for ActionListener instances in a small Swing application.
If I have a Controller, a MainFrame for the main JFrame and various JPanel containers ...
0
votes
1
answer
65
views
Drawing a 2D rectangle from Jtextfield inputs for GUI in Java
I am currently developing a GUI in Java. I am trying to display a 2D rectangle in a Jpanel called drawpanel in this case. In order to do this, I have created a class called die and initialized the ...
-1
votes
1
answer
84
views
Problem with Java, Swing, wait(), notify()
I am quiet new to Java and I try to make a simple turn-based game just to gain some experience. I have encounter a problem which I cannot solve on my own, despite I did quiet a lot of google research.....
0
votes
1
answer
79
views
Java swing controller view comunication don't perform
A Controller creates a new JFrame with a button. Using the actionListener is getting the order correctly but the action is asked to perform after is not working. Is asked to change a button name ...
0
votes
0
answers
21
views
How can I activate a button without it being pressed? [duplicate]
So I am trying to make a JButton get activated without it being actually pressed. However, I want this action to be performed only if a rectangle-jcomponent is touched by my player. How can I achieve ...
-1
votes
1
answer
45
views
Why I can't get medium level for math questions to appear?
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import javax.swing.border.*;
import java.awt.event.*;
public class MATHfighter extends JFrame implements ActionListener
{
Border ...
0
votes
0
answers
60
views
actionListener of a <p:commandButton not working in a <p:confirmDialog
I am using Prime Faces 7, JSF 2.3 and I have a <p:commandButton in a <p:confirmDialog.
But my actionListener is not being fired.
I tried many links, such as:
https://forum.primefaces.org/...
0
votes
1
answer
22
views
Label is not added in Jframe in an Externam function
i have created a button which is supposed to add "label" to my frame but it just doesn't work it prints "starting..." but not adds the "label" Here's my code
import javax....
0
votes
0
answers
21
views
Trying to make a JButton visible when a JTextField is tabbed out [duplicate]
I'm trying to use an action listener to set a button visible when something is in a text field.
The text field will only detect when enter is hit, it needs to also pick up on a tab out of the field. ...
0
votes
0
answers
32
views
Is there a click bubbling in Swing components?
In my Java Swing project, I want to listen to the same click on JPanel and on JButton at the same time. But it seems that when I click the button it fires actionPerformed only on this button.
0
votes
0
answers
82
views
Add photo in a button
class Actions implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Get the button that was clicked
JButton theButton = (JButton) e.getSource();
// ...
-2
votes
1
answer
70
views
How to listen for clicks on dynamically generated buttons in TableCell?
I have a class Task that takes field values from the database and is displayed as a row in the table.
package com.example.javafxapp.models;
import javafx.scene.control.Button;
import javafx.scene....
0
votes
1
answer
75
views
How to manually invoke actionPerformed in Java?
The method actionPerformed of class ActionListener is invoked when we click on a (let say) JButton. I want to run this method manually in a program. Is it possible?
Here is an example:
button....
0
votes
0
answers
18
views
ActionListener buttons only works for login or register, not both [duplicate]
I'm making an echo server in java, I have two buttons one for registration and one for login, I can login OR register but after that to use the other function I need to reopen the program.
When I ...
0
votes
1
answer
32
views
Java GUI, why isn't my carButton not displaying the picture I drew
For my program, I'm trying to display something that I drew with JRadioButtons and the images won't show up. I have system.out.println("test"); to see if my actionListener is working and its ...
1
vote
1
answer
38
views
How can I move the position of my Jcomponent after I click a button?
So I want to change the position of an image which I implemented as a JComponent after I click the corresponding button, however, it does not do anything when getting clicked.
I think the problem may ...
-2
votes
1
answer
52
views
Is it possible to add the same ActionListener for 100 buttons?
I have created an array of buttons (JButton[] jb = new JButton[100]) and I want to add the same action listener for all the buttons in the jb array instead of adding them one by one.
Just imagine ...
0
votes
1
answer
232
views
How to create a new user with each button click of a register form with Java?
I have a RegisterGui class which is my java swing gui. It has a username field, password field, and a register button.
I would like to have it so that each time the register button is clicked, it ...
-1
votes
1
answer
78
views
Swing Timer and ActionListener with StackOverflowError
I got a homework that I have tried for a long time and even asked professor about it and still not understand what gone wrong in this code. I have absolutely no idea on how to initialize time ( in ...
1
vote
1
answer
39
views
How to make a circle stop after revolving once or stop after 1 cycle?
So this is what I currently have. After I click the button, it should bounce from center to right and then left and then back to its original position. Then I should be able to click the button again ...
0
votes
0
answers
82
views
Multiple buttons in one table column in Java Swing won't perform action
What I need is to dynamically add buttons to one JTable column. Each row can have 0-N buttons in this column. I figured how to add these buttons but after clicking on them nothing happens, despite ...
0
votes
0
answers
27
views
JButton ActionListener is working for some methods but not others
I'm trying to create a button that can read settings from a file, then repaint the GUI with the selected settings so it's easy to review. Additionally, I would like a button to delete a selected file.
...
1
vote
2
answers
54
views
JFrame doesn't appear with ActionListener
I'm a beginner and I've written this code but it does not seem to work. I've run the code and for some reasons the JFrame does not appear (the class name is in Hungarian, do not mind it).
import ...