import java.awt.Graphics;
import javax.swing.JApplet;

/* <applet code="Guruguru.class" width="200" height="150"> </applet> */

public class Guruguru extends JApplet implements Runnable {
  int r=50, x=110, y=70;
  double theta=0; // 角度
  Thread thread=null;

  @Override  
  public void paint(Graphics g) {
    super.paint(g); // スーパークラスのpaintを呼び出す
                    // 全体を背景色で塗りつぶす。
    g.drawString("Hello, World!", x, y);
  }
  
  @Override  
  public void start() {
    if (thread == null) { // 念のためチェック
      thread = new Thread(this);
      thread.start();
    }
  }

  @Override    
  public void stop() {
    thread = null;
  }
  
  public void run() {
    Thread thisThread = Thread.currentThread();
    for(; thread == thisThread; theta+=0.02) {
      x = 60+(int)(r*Math.cos(theta)); y = 70-(int)(r*Math.sin(theta));
      repaint();  // paintを間接的に呼出す
      try {
        Thread.sleep(30); // 30 ミリ秒お休み
      } catch (InterruptedException e) {}
    }
  }
}
