import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.awt.Dimension; /* */ public class ThreadTest6 extends Applet implements Runnable{ Thread thread = null; int x; Dimension size; public void init(){ x = 10; size = getSize(); thread = new Thread(this); thread.start(); } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ g.setColor(getBackground()); g.fillRect(0, 0, size.width, size.height); for (int j = 0 ; j < 100 ; j++){ for (int i = 0 ; i < 255 ; i++){ g.setColor(new Color(i, 0, 0)); g.drawLine(x + i, 10, x + i, 265); } for (int i = 0 ; i < 127 ; i++){ g.setColor(new Color(0, 0, i * 2)); g.drawLine(x, 10 + i * 2, x + 255, 10 + i * 2); } } } public void run(){ while(true){ x += 1; if (x >= 100){ x = 10; } repaint(); /* 200ミリ秒待機する */ try{ Thread.sleep(200); }catch (InterruptedException e){ } } } }