//////////////////////////////////////////////////////////// // OVERRIDEN //////////////////////////////////////////////////////////// @Override public void actionPerformed(ActionEvent e) { // System.out.println( "timer event (1) !"); if (e.getActionCommand().equals("remote bead animator")) { availableBeads[currentBead - 1].animation(5); int tolerance = 5; if (availableBeads[currentBead - 1].getY() > (int) (pegs[insertedInPegNum - 1].getBounds().getMaxY() - availableBeads[currentBead - 1].getBounds().getHeight() - (availableBeads[currentBead - 1].getBounds().getHeight() + tolerance) * (pegs[insertedInPegNum - 1].amountOfBeads2() - 1))) { // here the remote player finished moving remoteBeadAnimTimer.stop(); // keep reading from refereee!!!!!! try { receiveFromReferee(); } catch (InterruptedException e1) { e1.printStackTrace(); } } // end if repaint(); // happens every time the animationTimer triggers an event } else if (e.getActionCommand().equals("images are loaded")) { // images are loaded, then just paint them // this only happens one time after user // clicked in new game menu repaint(); } else if (e.getActionCommand().equals("is win_lose")) { // images are loaded, then just paint them // this only happens one time after user // clicked in new game menu repaint(); startImageLoader(LOSE_IMAGE_FILE); updateWhenLoaded.stop(); } else if (e.getActionCommand().equals("Gertrude vs Computer")) { // starts the worker that receives from refereee try { receiveFromReferee(); // this is a worker } catch (InterruptedException e1) { System.out.println("COuldnt receive from referee"); } } else if (e.getActionCommand().equals("animation")) { availableBeads[currentBead - 1].animation(5); int tolerance = 5; if (availableBeads[currentBead - 1].getY() > pegs[insertedInPegNum - 1].getBounds().getMaxY() - availableBeads[currentBead - 1].getBounds().getHeight() - (availableBeads[currentBead - 1].getBounds().getWidth() + tolerance) * (pegs[insertedInPegNum - 1].amountOfBeads2() - 1)) { animationTimer.stop(); // send to the referee the user's move System.out.println("GUI, I sent " + insertedInPegNum); sendToReferee(Integer.toString(insertedInPegNum)); // here the local player finished moving a piece, // now its turn of the remote player to go! // starts the worker that receives from refereee try { receiveFromReferee(); // this is a worker } catch (InterruptedException e1) { System.out.println("Couldnt receive from referee"); } } // end if repaint(); } // end if-else }