JAVAアプレットのイメージファイル表示サンプルです。ソースコード及びサンプルHTMLは
ダウンロード
コーナー入っています。
複数イメージを読み込み、表示させるアプレットサンプルです。
4種類のスクロールタイプを設定できますので、好みに合わせて
使用してください。また、読み込み完了待ち処理を追加しています

基本パラメータは timer Int 表示を呼び出すタイミングを指定 images Int イメージファイルの数 imageX String イメージファイル名指定(例: <param name=image1 value=/~kitaro/gif/title.gif> ) type string スクロールタイプ指定(up,down,left,right) scroll Int スクロール分割数 delay Int イメージ表示毎の停止時間

// JAVA applet sample 'DrawImagesScroll.java' for kitaro C3Lab JAVA lab
// copyright (c) by kitaro 1996
// このプログラムはCGイメージを表示するアプレットサンプルです
//
// timer : イメージファイル表示時間
// images : イメージファイルの数
// imageX : イメージファイル名(X = イメージナンバー)
// type : up,down,left,right
// scroll : スクロール分割数
// delay : スクロール毎の待ち時間
import java.applet.*;
import java.awt.*;
import java.net.*;
public class DrawImagesScroll extends java.applet.Applet implements Runnable {
String temp;
//
Thread thread;
int wx,wy;
int timer,count,waiting;
// background job
MediaTracker mt;
Graphics og;
Image oimage;
int images;
Image image[];
// scroll val;
String type;
int nType,nCount,nCountOrg,nCountWidth;
int nScrollCount;
int nDelay;
boolean bDlayflg;
//
int c1,c2;
int x1,x2,y1,y2;
// int ofs;
public void init(){
String wall;
int i;
temp = getParameter("timer"); if(temp==null)temp="100"; timer = Integer.valueOf( temp ).intValue();
temp = getParameter("wait"); if(temp==null)temp="100"; waiting = Integer.valueOf( temp ).intValue();
temp = getParameter("images"); if(temp==null)temp="2"; images = Integer.valueOf( temp ).intValue();
temp = getParameter("wait"); if(temp==null)temp="3000"; nDelay = Integer.valueOf( temp ).intValue();
type = getParameter("type"); if(type==null)type="up";
temp = getParameter("scroll"); if(temp==null)temp="20"; nCountOrg= Integer.valueOf( temp ).intValue();
mt = new MediaTracker(this);
// Loading Images
image = new Image[images];
for(i=0;i=images)c2=0;
switch(nType){
case 0 :
y1 = nCountWidth*nScrollCount;
if(y1 >= wy) y1=wy;
y1 = 0 - y1; y2 = y1 + wy; break;
case 1 :
y1 = nCountWidth*nScrollCount;
if(y1 >= wy) y1=wy;
y2 = y1 - wy; break;
case 2 :
x1 = nCountWidth*nScrollCount;
if(x1 >= wx) x1=wx;
x1 = 0 - x1; x2 = x1 + wx; break;
case 3 :
x1 = nCountWidth*nScrollCount;
if(x1 >= wx) x1=wx;
x2 = x1 - wx; break;
}
if(++nScrollCount>nCountOrg) {nScrollCount=0; return 1;}
return 0;
}
public void off_update(){
if( scroll(count)!=0){
if( ++count >= images) count=0;
bDlayflg = true;
}
}
//*******************************************************************
public void start(){
thread = new Thread(this);
thread.start();
}
public void run (){
try{mt.waitForAll();}
catch(InterruptedException e){showStatus(e.toString());return;}
while(true)
{
bDlayflg = false;
try{ thread.sleep(timer);}
catch(Exception e){showStatus(e.toString());}
off_update();
if(bDlayflg==true)
{
try{ thread.sleep(nDelay);}
catch(Exception e){showStatus(e.toString());}
}
repaint();
}
}
public void paint(Graphics g){
og.drawImage(image[c1],x1,y1,new Color(0),this);
og.drawImage(image[c2],x2,y2,new Color(0),this);
g.drawImage(oimage,0,-2,new Color(0),this);
}
public void update(Graphics g){paint(g); }
}

サンプルHTML <html> <head> <title>DrawImagesScroll</title> </head> <body> <hr> <applet code=DrawImagesScroll 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> <param name=type value=left> <param name=scroll value=20> </applet> </body> </html> <hr>
