Presentation is loading. Please wait.

Presentation is loading. Please wait.

11-Jun-15 Corrections. Pausing I On my HTML page, I said to pause like this: private void interpret(Tree node) { if (stopped) return; if (paused) { try.

Similar presentations


Presentation on theme: "11-Jun-15 Corrections. Pausing I On my HTML page, I said to pause like this: private void interpret(Tree node) { if (stopped) return; if (paused) { try."— Presentation transcript:

1 11-Jun-15 Corrections

2 Pausing I On my HTML page, I said to pause like this: private void interpret(Tree node) { if (stopped) return; if (paused) { try { currentThread().wait(); } catch (InterruptedException e) { } }... } The code for pausing is completely wrong, but it’s in the right place

3 Pausing II In my threads.ppt lecture, which I posted but forgot to link to, I said to pause like this: public void run( ) { while (okToRun) { while (paused) { try { Thread.sleep(100); } catch (InterruptedException e) { } }... main loop... } } This is more nearly correct, but it shouldn’t be in the run method

4 Pausing III The run method takes no parameters and just calls the interpret method (with a predefined parse tree): public void run() { interpret(program); } The highly recursive interpret method is where you need to check for pausing and stopping: private void interpret(Tree node) { if (stopped) return; while (paused) { // while, not if try { Thread.sleep(100); // not currentThread().wait() } catch (InterruptedException e) { } }... }

5 The revised BoardGame.zip The second version of BoardGame.zip does have the necessary corrections; the most important of these is that piece.remove() no longer calls removeHelper() Although it has corrections, there is some cruft that I failed to clean out Most important, Piece.toString() calls a special-purpose method, getColorName, which I did not provide Piece.toString() should look like this: public String toString() { return getClass().getName() + "[" + row + "][" + column + "]"; }


Download ppt "11-Jun-15 Corrections. Pausing I On my HTML page, I said to pause like this: private void interpret(Tree node) { if (stopped) return; if (paused) { try."

Similar presentations


Ads by Google