3 Replies Latest reply: Dec 10, 2012 9:20 AM by 969557 RSS

    Wait the user for action!

    978593
      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?


      Thanks for your attention and time!!
        • 1. Re: Wait the user for action!
          Kayaman
          975590 wrote:
          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?
          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?
          • 2. Re: Wait the user for action!
            gimbal2
            975590 wrote:
            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!
            That is a contradiction. The button is part of the application, so how can the user press it when you 'stop the program'?

            Let me make a guess: you actually want to disable certain components until the user presses that button.
            • 3. Re: Wait the user for action!
              969557
              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.