import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; /* */ public class ThreadTest5 extends Applet implements Runnable{ Thread thread = null; int x, y; Color col; public void init(){ x = 10; y = 10; col = new Color(255, 0 ,0); thread = new Thread(this); thread.start(); } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ g.setColor(col); g.drawOval(x, y, 50, 50); } public void run(){ while(true){ x = (int)(Math.random() * 100); y = (int)(Math.random() * 100); int red = (int)(Math.random() * 255); int green = (int)(Math.random() * 255); int blue = (int)(Math.random() * 255); col = new Color(red, green, blue); repaint(); /* 500ミリ秒待機する */ try{ Thread.sleep(500); }catch (InterruptedException e){ } } } }