//************************************************************* // Java application // 「ImageAnimationTest」 // //          作 成 者:ルート高菜    //          作成開始月:2006/6 //          最終更新月:2006/6 [TN084/J74] //************************************************************* import java.awt.*; import java.io.File; import javax.swing.*; public class ImageAnimationTest extends JFrame{ // public static void main(String[] args) { ImageAnimationTest frame=new ImageAnimationTest(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // Image[] images1; Image[] images2; Image[] images3; //コンストラクタ public ImageAnimationTest(){ setTitle("ImageAnimationTest"); setSize(400,500); //Applecationでのイメージ取得方法その1(MediaTrackerを使わなくてもいいらしい) ImageIcon[] imageIcon=new ImageIcon[4]; images1=new Image[4]; for(int i=0;i<4;i++){ imageIcon[i]=new ImageIcon(getClass().getResource("image/0"+(i+1)+".gif")); images1[i]=imageIcon[i].getImage(); } //Applecationでのイメージ取得方法その2 images2=new Image[4]; MediaTracker mt=new MediaTracker(this); for(int i=0;i<4;i++){ images2[i]=Toolkit.getDefaultToolkit().getImage("image/0"+(i+1)+".gif"); mt.addImage(images2[i],0); } try{ mt.waitForID(0); }catch(InterruptedException e){ } //Applecationでのイメージ取得方法その3 images3=new Image[4]; String dir=System.getProperty("user.dir")+File.separator; mt=new MediaTracker(this); for(int i=0;i<4;i++){ images3[i]=Toolkit.getDefaultToolkit().getImage(dir+"image/0"+(i+1)+".gif"); mt.addImage(images3[i],0); } try{ mt.waitForID(0); }catch(InterruptedException e){ } //アニメーション用の専用パネル AnimationPanel animationPanel=new AnimationPanel(); //コンテナ枠 Container cp=getContentPane(); cp.add(animationPanel); } //swingでは描画用に中身を記述したパネルを作らねばならない(内部クラス) class AnimationPanel extends JPanel implements Runnable { // private Thread thisThread; //コンストラクタ public AnimationPanel(){ //背景色を設定しておく setBackground(Color.BLACK); // thisThread=new Thread(this); thisThread.start(); } //swingにおける描画メソッド public void paintComponent(Graphics g){ super.paintComponent(g); //必要(これがないと背景色で塗りつぶされない) //パネルのサイズいっぱいに升目を描画(負荷をかけ、ちらつきを確かめるため) g.setColor(Color.GRAY); for(int w=1;w