JAVAアプレットのイメージファイル表示サンプルです。ソースコード及びサンプルHTMLは
ダウンロード
コーナー入っています。
このアプレットはバックグラウンドイメージ処理で画面のずれに対応しています。
基本パラメータは timer 表示を呼び出すタイミングを指定 wx 表示エリアX座標サイズ wy 表示エリアY座標サイズ images イメージファイルの数 imageX イメージファイル名指定(例: <param name=image1 value=/~kitaro/gif/title.gif> )
// JAVA applet sample 'DrawImages.java' for kitaro C3Lab JAVA lab // copyright (c) by kitaro 1996 // このプログラムはCGイメージを表示するアプレットサンプルです // バックグラウンド処理対応にしました // wx : エリアサイズX座標 // wy : エリアサイズY座標 // timer : イメージファイル表示時間 // images : イメージファイルの数 // imageX : イメージファイル名(X = イメージナンバー) import java.applet.*; import java.awt.*; import java.net.*; public class DrawImages extends java.applet.Applet implements Runnable { String temp; // Thread thread; int timer,count,waiting; // background job MediaTracker mt; Graphics og; Image oimage; int wx,wy; int images; Image image[]; // boolean job; public void init(){ String wall; int i; temp = getParameter("wx"); if(temp==null)temp="200"; wx = Integer.valueOf( temp ).intValue(); temp = getParameter("wy"); if(temp==null)temp="200"; wy = Integer.valueOf( temp ).intValue(); temp = getParameter("timer"); if(temp==null)temp="100"; timer = Integer.valueOf( temp ).intValue(); temp = getParameter("wait"); if(temp==null)temp="20"; waiting = Integer.valueOf( temp ).intValue(); temp = getParameter("images"); if(temp==null)temp="1"; images = Integer.valueOf( temp ).intValue(); // Loading Images image = new Image[images]; for(i=0;iimages) count=0; } } public void off_clear(){ if(image[count]==null) og.fillRect(0,0,wx,wy ); else{ int sx,sy; try{ sx = image[count].getWidth(this); sy = image[count].getHeight(this); if((sx>0)&&(sy>0)){ og.drawImage(image[count],0,0,new Color(0),this); } }catch(Exception e){} } } public void off_update(){ off_clear(); } public void paint(Graphics g){ g.drawImage(oimage,0,0,new Color(0),this); } public void update(Graphics g){paint(g); } }
サンプルHTML <html> <head> <title>DrawImages</title> </head> <body> <hr> <applet code=DrawImages width=200 height=200> <param name=timer value=1000> <param name=images value=2> <param name=image1 value=/~kitaro/gif/title.gif> <param name=image2 value=/~kitaro/gif/title2.gif> </applet> </body> </html> <hr>