Results 1 to 5 of 5
Thread: is there a way to pause java?
- 04-24-2010, 06:41 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
- 04-24-2010, 07:01 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
The usual way to make GUIs is to make them event driven, i.e. do something based on an event that happens, such as pressing a button or entering text, so you don't pause the program, but leave the program idle until something happens. See a few tutorials about using ActionListeners, things should be clearer then.
- 04-24-2010, 07:20 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
yea that is what i want to do. i want to leave the program idle. any ideas how to do it?
in my code, while waiting for the user to press enter, the program runs theJava Code:class enterp implements ActionListener { public void actionPerformed(ActionEvent enterpressed) { gues = guess.getText(); System.out.println(gues); } } enterp entered = new enterp(); guess.addActionListener(entered); try { Thread.sleep(6000); } catch(InterruptedException e) { } double answer = Double.parseDouble(gues); System.out.println(answer);
this results in an error since gues is a null...any ideas on how to not run that 2 lines of code before the user presses enter?Java Code:double answer = Double.parseDouble(gues); System.out.println(answer);
- 04-24-2010, 07:26 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
You would do that by calling the method you want to run from inside the actionPerformed() method. So, while there is no input, the program does nothing, when you press the button, you execute the piece of code you want to.
-
Agrees with moon. What you want to achieve is already done for you with the Swing event-driven programming model. The last thing that you want to do is to call Thread.sleep(...) inside of your GUI code.
Similar Threads
-
How to pause
By ravjot28 in forum Threads and SynchronizationReplies: 0Last Post: 03-31-2010, 06:09 AM -
Make Java Pause
By FlyNn in forum New To JavaReplies: 2Last Post: 02-10-2010, 10:18 AM -
Pause and Continue Long Cycles
By pedro123 in forum Threads and SynchronizationReplies: 2Last Post: 07-28-2009, 07:47 AM -
pause until JFrame is closed.
By Tamu in forum Advanced JavaReplies: 8Last Post: 11-30-2008, 09:46 PM -
Help with Pause
By trill in forum Java AppletsReplies: 2Last Post: 09-28-2007, 08:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks