package applet; import java.applet.Applet; import java.awt.*; //アニメーション アプレット改良版 //拡大・縮小する円 public class App15 extends Applet implements Runnable { int x,y,w,h; static int Ovalx = 100; //xは、右・左移動の状態を示す boolean idou = true; //true 左ー>右 //false 左<−右 public void init() { setBackground(Color.white); setForeground(Color.red); //別処理スレッドを開始 Thread th = new Thread(this); th.start(); } //アプレット表示スレッドとは別の //x座標更新スレッド public void run() { try { //無限ループ while (true) { //再度paint()を呼ぶ repaint(); //移動速度 Thread.sleep(10); if (idou){ //拡大する円 x++; y++; w++; h++; //起動時のx座標加算 Ovalx++; }else{//左 <- 右 Ovalx--; //縮小する円 x--; y--; w--; h--; } //右サイドの壁の位置=350 if (Ovalx >= 500) idou = false; //左サイドの壁の位置=0 if (Ovalx <= 0) idou = true; } } catch (Exception err) { } }//run() public void paint(Graphics g) { //楕円を描くメソッド //Ovalx=表示x座標 //x座標がrun()で更新 g.fillOval(x, y, w, h); g.fillRect (75, Ovalx, 50, 50); g.fillOval(Ovalx, 75, 100, 100); } }