import java.awt.*; import javax.swing.*; /* */ public class Guruguru10 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(10); // 10 ミリ秒お休み } catch (InterruptedException e) {} } } public static void main(String[] args) { JFrame frame = new JFrame("ぐるぐる!"); JApplet applet = new Guruguru10(); applet.setPreferredSize(new Dimension(200, 150)); frame.add(applet); frame.pack(); frame.setVisible(true); applet.init(); applet.start(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }