Results 1 to 8 of 8
Thread: break or stop for loop
- 09-12-2011, 08:02 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
break or stop for loop
Hi everybody..............
I have small but serious problem. The problem is I have two button -"START" and "STOP"
So when I will click on START button it simply do the following----
actionPerformed(ActionEvent e){
if(e.getSource(STARTbuttonObject){
for(int i=0;i<=5000;i=i+0.1){
System.out.println(i);
}
}
}
now I want to stop the running for loop by clicking on the STOP button. So how can I do it?
Please explain.
Thank you.
- 09-12-2011, 08:20 PM #2
Re: break or stop for loop
You're going to have to take a different approach. Since both of your ActionListeners are going to fire on the same Thread (the EDT), the STOP button has to wait until the START button has completed.
You might want to look into threading, or adding a Timer.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-12-2011, 08:26 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
- 09-12-2011, 08:33 PM #4
Re: break or stop for loop
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-12-2011, 08:38 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
- 09-12-2011, 08:40 PM #6
Re: break or stop for loop
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 09-12-2011, 08:46 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
- 09-12-2011, 11:39 PM #8
Similar Threads
-
Having a problem with the loop and how to stop it at the correct place.
By JR2010 in forum New To JavaReplies: 7Last Post: 04-02-2011, 06:15 PM -
how to stop for loop
By rjagan in forum New To JavaReplies: 3Last Post: 04-01-2011, 04:15 PM -
help!, while loop wont stop!
By crank6015 in forum New To JavaReplies: 4Last Post: 03-24-2011, 02:27 AM -
Use stop button to stop moving (stop timers) on JPanel
By mneskovic in forum New To JavaReplies: 3Last Post: 07-23-2010, 12:50 PM -
Counting with a delayed loop and using button to break
By danmc in forum New To JavaReplies: 1Last Post: 03-03-2009, 12:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks