/** * @file AutoRotate.java * @author Robert S. Laramee * @see DrawCanvas.java *
* This class runs the auto rotoate function. It's a separate class because * it's must to be it's own thread, so the application thread may still handle * user input events while our objects are rotating. Otherwise, the objects * will rotate forever! */ import java.awt.*; import java.awt.event.*; class AutoRotate extends Thread { private DrawCanvas canvas; public AutoRotate(DrawCanvas c) { canvas = c; } /** * setAutoRotateMode *
* Beware, the paint() method will not clear the old shape(s) off of the * canvas. It will only add new ones * * @param newRotateMode -the axis about which to rotate */ public void run () { if (canvas.getAutoRotateMode() == DrawCanvas.STOP) { return; } Graphics g = canvas.getGraphics(); while (canvas.getAutoRotateMode() != DrawCanvas.STOP) { try { Thread.sleep(canvas.getSleepTime()); if (canvas.getAutoRotateMode() == DrawCanvas.ROTATEX) { View.rotate( "x", canvas.getDegreesX() ); canvas.setDegreesX(); } else if (canvas.getAutoRotateMode() == DrawCanvas.ROTATEY) { View.rotate( "y", canvas.getDegreesY() ); canvas.setDegreesY(); } else if (canvas.getAutoRotateMode() == DrawCanvas.ROTATEZ) { View.rotate( "z", canvas.getDegreesZ() ); canvas.setDegreesZ(); } else if (canvas.getAutoRotateMode() == DrawCanvas.STOP) { break; } canvas.update(g); } catch (InterruptedException e) { System.err.println("** Error: InterrruptException " + e); } } } }