import java.awt.*; public class Ball extends Thread { int w = 15; int h = 15; int x = 0; int y = 0; int dx = 2; int dy = 2; boolean cont = true; public Ball(int dx, int dy, int w, int h) { this.w = w; this.h = h; this.dx = dx; this.dy = dy; } public void run() { while (cont) { move(); try { sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } } } void draw(Graphics g) { //System.out.println(&quot;draw ball&quot;); g.fillOval(x, y, 5, 5); } public void move() { x += dx; y += dy; if (x <= 0) { x = 0; dx = -dx; } if (x >= w) { dx = -dx; } if (y <= 0) { y = 0; dy = -dy; } if (y >= h) { y = h; dy = -dy; } } public void tstop() { cont = false; } }