package com.torn.sample;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;


@SuppressWarnings("serial")
public class Main_MoveCircle extends JFrame implements Runnable {
	/* 定数 */
	private static final int SIZE = 600;
	private static final int OFFSET = SIZE / 2;
	
	public static void main(String[] args) {
		new Thread(new Main_MoveCircle()).start();
	}
	public Main_MoveCircle() {
		setTitle("円運動");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(SIZE , SIZE );
		setVisible(true);
	}

	private static final double THETA = Math.PI / 12;
	private int t = 1;

	public void paint(Graphics g) {
//		super.paint(g);
		
		/* 座標取得 */
		int x, y;
		final int r = 50;
		double wt = THETA * t;
		
		x = (int)(r * Math.cos(wt));
		y = (int)(r * Math.sin(wt));
		t++;

		/* 描画 */
		g.setColor(Color.CYAN);
		g.fillOval(OFFSET + x, OFFSET + y, 12, 12);
	}

	public void run() {
		while(true) {
			repaint();
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
