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. I tried to use Graphics2D to set each color for the tool according to the button clicked in the palette. I tried to
Tag: actionlistener
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. There is a controller that fills the rows of the table with objects of the Task class. I need to listen for clicks on buttons in cells. But those buttons are not present as fields in the controller. How
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 every time I click one of the buttons displayed on the screen and it will print out the index of that button
How to create an array with random numbers and send it to listener without randomizing it again?
So i’m trying to create a program that create an array of 100 random numbers (without changing everytime user reacts to it), and allow users to check the numbers by entering the index of it. However, the array keep randomizing everytime the user pressed the Show Element button. I also tried to create the array on the main program, but
How to have the program regenerate a “new game” where previous grid letters get swapped with new grid letters
In this program I’m trying to input a functionality to start game, where if I click start game (MainMenu) a new jpanel opens up (MainGame), creating another jpanel that creates jbuttons in a grid. If i go back, and click start game again, a new grid should generate instead of the previous one, effectively starting a “new game”. the problem
How do I get a variable collected from a JTextField and give it to a getter method?
Very new to using Java and spent hours looking for a solution, but I cannot find out how to get the input collected by a JTextField with a button and ActionListener then be used for a getter method that can receive idNum so I can use the input in another class. Answer I believe what you are trying to do
How to trigger another action listener after completion of ActionListener?
I created a GUI with a JFrame, JPanel, JLabel and a JButton. I added the button and the label to the panel. I added two ActionListeners for the button. I want to execute the first action listener. Then execute the other one. Basically, I have some text that I want to output in the label, sequentially. I want for it
I want the city selected in the first combo box not to appear in the second
If I choose a city FROM: JComboBox then it shouldn’t appear in TO: combo box. How can I code the ActionListener of this action listener? Screenshot Code: Answer I reworked your code to get away from static. You only need one list of cities for your from and to JComboBoxes. You use an ActionListener to listen for changes in the
Is there a way to skip a mouse click for ActionListener?
I have a Tic Tac Toe GUI that lets a user play against a computer. I use an actionListener to receive the users mouse clicks on where they want to put their “X” on the board. The problem I have is, the way my code is set up, my GUI waits for a mouse click whenever it’s the computers turn
How to make a Java AWT Action Listener run multiple times
I have this code and I’m trying to have one action listener be used, and it be used multiple times. I have tested this code over and over again, and I have figured out that it is only running actionPerformed one time (When you click the “Login” button) Is there a way that I can fix this so that I