import java.awt.*; import javax.swing.*; public class Ex10_4 extends JPanel implements Runnable { int x, y, vel, wid, hei, dia; double theta; Thread thd = null; // スレッド public Ex10_4() { // コンストラクタ setOpaque(false); // 前絵を消してから描画 x = 10; y = 10; // 描画ボールの初期位置(x,y) dia = 50; // 描画ボールの直径 diameter vel = 10; // 描画ボールの速度 velocity theta = Math.PI/6; // 描画ボールの射出方向(π/6) wid = 500; hei = 300; // 画面サイズ thd = new Thread(this); thd.start(); // スレッド開始 } public void paintComponent(Graphics g) { g.setColor(Color.blue); // 色設定 g.fillOval(x,y, dia,dia); // 楕円描画(ビリヤードボール) } public static void main(String[] args) { JFrame app = new JFrame(); app.add(new Ex10_4()); app.setTitle("ビリヤードボール アニメ"); app.setSize(500, 300); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); app.setVisible(true); } public void run() { while (true) { if (0=hei-dia) { theta = 2*Math.PI - theta; } else if (x<=0 || x>=wid-dia) { if (0<=theta && theta