/*--------------------------------------------- rep12ans.java 解答例:ハッピーニューイヤー・カウントダウン ----------------------------------------------*/ import java.applet.*; import java.awt.*; import java.util.Random; /* */ public class rep12ans extends Applet implements Runnable { Thread thd = null; Color col; Random rnd; int cnt, red, grn, blu; public void init() { // 初期化処理 cnt = 10; // カウンター初期値 red = 255; grn = 125; blu = 0; col = new Color(red, grn, blu); rnd = new Random(); thd = new Thread(this); // 新しいスレッドを作る thd.start(); // スレッド開始 } public void paint(Graphics g) { // 描画処理 g.setColor(col); if (cnt == 0) { g.setFont(new Font("Dialog", Font.PLAIN, 24)); g.drawString("Happy New Year!", 5, 55); } else { g.setFont(new Font("Dialog", Font.PLAIN, 72)); g.drawString("" + cnt, 60, 80); } } public void run() { while (cnt >= 0) { repaint(); red = rnd.nextInt(256); grn = rnd.nextInt(256); blu = rnd.nextInt(256); col = new Color(red, grn, blu); try { thd.sleep(2000); } catch (InterruptedException e) { } cnt--; } } }