This content has been marked as final. Show 3 replies
975590 wrote:Sounds like you're doing things completely wrong. You don't need to have a while loop in an event based system like Swing. What does your code look like?
Hello, i have a GUI with JButtons and JTextarea which show to the user what is pressing and my problem is who to stop the program and wait the user until press a specific button! I have create a while to wait until the user press the specific button, but i don't like this solution! Any ideas?
975590 wrote:That is a contradiction. The button is part of the application, so how can the user press it when you 'stop the program'?
Hello, i have a GUI with JButtons and JTextarea which show to the user what is pressing and my problem is who to stop the program and wait the user until press a specific button!
Let me make a guess: you actually want to disable certain components until the user presses that button.
Just to make sure the basics are covered:
If you have a main method that creates the GUI and makes it visible, you dont need to stay in that main method to keep the program running. Main method execution can end and the GUI is still visible. This is because Java AWT/Swing components invisibly launches a separate thread to run the GUI components.
To execute some code when user clicks the button, you need to link that code to button click event. For that, the Swing tutorial provides good help.