//BouncingTime.java //moving circle with a time-killing loop in paint import java.awt.*; import javax.swing.*; public class BouncingTime extends JApplet { int count, size, movesize, killtime; public void init() { String input; input = JOptionPane.showInputDialog( "Enter number of loops" ); count = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter size of circle" ); size = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter distance of move" ); movesize = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter time killing loops" ); killtime = Integer.parseInt( input ); } public void paint (Graphics g) { int x=(int)(Math.random()*getWidth()); //random starting int y=(int)(Math.random()*getHeight()); int dir=(int)(Math.random()*4); //random diagonal direction: //0 is NE, 1 is SE, 2 is SW, 3 is NW for (int i=1; i<=count; i++) { g.setColor( Color.WHITE ); g.fillOval(x,y,size,size); //erase current circle if (dir == 0) { //moving NE x = x + movesize; y = y - movesize; if (y <= 0) //hit top, dir = 1; //change to SE. else if (x >= getWidth()) //hit right, dir = 3; //change to NW } else if (dir == 1) { x = x + movesize; y = y + movesize; if (x >= getWidth()) dir = 2; else if (y >= getHeight()) dir = 0; } else if (dir == 2) { x = x - movesize; y = y + movesize; if (x <= 0) dir = 1; else if (y >= getHeight()) dir = 3; } else if (dir == 3) { x = x - movesize; y = y - movesize; if (y <= 0) dir = 2; else if (x <= 0) dir = 0; } g.setColor( Color.RED ); g.fillOval(x,y,size,size); for (int j=1; j