Hi,
I have a top level window called mainFrame that has buttons called "Start", "Stop", and "Pause".
I want the pause button to pause a Depth First Search thread called Search.DFS() and then resume when the "Start" button is pressed again.
I read the example at http://forums.sun.com/thread.jspa?forumID=54&threadID=5240475 is this the correct way of doing this?
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
stopButton.setEnabled(true);
if (startButton.getText().equals("Start")) {
startButton.setText("Pause");
search = new Search(this); // start search
} else {
startButton.setText("Start");
// insert code to pause here... I'm not sure how to do this yet...
//search.pause();
}
}
private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {
stopButton.setEnabled(false);
startButton.setEnabled(true);
startButton.setText("Start");
//search.stopme();
}
Then inside my Search class/thread I have the following code... that has access to mainFrame my top level window...
public class Search extends Thread {
TopLevel mainFrame;
public Search(JavaSpiderView mFrame) {
super("Search Thread");
mainFrame = mFrame;
start();
}
public void run() {
setup();
DFS();
}
public void pause() {
}
public void stopme () {
}
public void DFS() {
// depth first search code this takes a long time I want the user to be able to pause or stop this.
}
return;
}
}
I would like to create two new methods inside my Search class one called search.pause() and another called search.stopme() that I can call from my mainFrame.
Any ideas?
Thanks,
V$h3r
Edited by: Vsh3r on Apr 7, 2010 4:18 PM
Edited by: Vsh3r on Apr 7, 2010 4:19 PM
Edited by: Vsh3r on Apr 7, 2010 4:35 PM