import java.awt.*; // AWT(AbstractWindowingToolkit): Graphics import java.awt.image.*; // BufferedImage など import java.io.*; // File など import javax.swing.*; // Window, GUI: JPanel, JFrame import javax.imageio.*; // ImageIO public class Ex11_1 extends JPanel implements Runnable { int x, y, vel, wid, hei, dia; double theta; BufferedImage img = null; // 画像用 BufferedImage img2 = null; // 画像用 Thread thd = null; // スレッド public Ex11_1() { // コンストラクタ try { img = ImageIO.read(new File("img/teku.gif")); // 画像の読み込み img2 = ImageIO.read(new File("img/nyan2.gif")); // 画像の読み込み } catch (Exception e) { e.printStackTrace(); } setOpaque(true); // 前絵を消してから描画 x = 10; y = 10; // 画像初期位置(x,y) dia = 50; // 画像の縦横サイズ(ダミー) vel = 10; // 画像の移動速度 velocity theta = Math.PI/6; // 描画ボールの射出方向(π/6) wid = 500; hei = 300; // 画面サイズ thd = new Thread(this); thd.start(); // スレッド開始 } public void paintComponent(Graphics g) { // 描画用メソッド g.drawImage(img, x, y, this); // 図形1(img)描画 g.drawImage(img2, x, x, this); // 図形2(img2)描画 } public static void main(String[] args) { // mainメソッド JFrame app = new JFrame(); app.add(new Ex11_1()); app.setTitle("画像反射アニメ"); app.setSize(500, 500); 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