Results 1 to 2 of 2
Thread: stopping thread...using flags
- 07-31-2008, 09:29 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 6
- Rep Power
- 0
stopping thread...using flags
I have a Gui in which I have animation placed in the thread (Runner). I want the thread to stop when the user pushes the stop button (in a different panel than the animation. Originally I had set up a flag variable in the thread to make it stop until I realized that I would have to create checks for the variable and the animation would continue playing until it reached one of the check points. Is there a way/ another option to make the thread stop quickly. Thank you for any help you offer!
Below is my current code:
And the Action Listener for the stop button:Java Code:class Runner extends Thread { public SimulationPanel sp; public volatile boolean isRun; public void run() { while (!isRun){ System.out.println("is Run is " + isRun); Boolean isVisible = true; for(int i = 0; i<10; i++){ if (isVisible ==true) { sp.setRepaintValue(SimulationPanel.RepaintType.REMOVERIGHTLINE); isVisible = false; delay(100); }else if (isVisible == false){ sp.setRepaintValue(SimulationPanel.RepaintType.RIGHTLINE); sp.repaint(); delay(100); isVisible = true; } } if(isRun) return; ......} public void stopThread() { System.out.println("stopThread method executing properly"); isRun = true; }
Java Code:else if (command.equals ("stop")) { new Timer(true).schedule(new TimerTask() { public void run() { System.out.println("Requesting stop"); runnerThread.stopThread();} }, 5); }
- 07-31-2008, 09:36 PM #2
Similar Threads
-
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 10:30 PM -
How to get thread name
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:40 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM -
using Thread
By one198 in forum New To JavaReplies: 1Last Post: 11-21-2007, 08:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks