|  |
クリックでスクロール方向転換(上下左右可能)
写真:いすゞ本社ビル大森ベルポート
DownLoad Panorama.lzh(ソースコード付き)
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////
// Java Panorama Applet /I-ichirow Suzuki
//
import java.applet.Applet;
import java.awt.*;
//---------------------------------------------------------------------------------------------
public class Panorama extends Applet implements Runnable
{
Thread thread;
int appwidth;
int appheight;
int stime;
int step;
int nowstep;
int mode;
int status;
int x;
int y;
Image image;
MediaTracker mt;
boolean mouseflag;
int imgwidth;
int imgheight;
Image offimg;
Graphics offscr;
final String STATUSTEXT = "Panorama Applet";
//--------------------------------------------------------
public Panorama()
{
}
//--------------------------------------------------------
public void init()
{
stime = 120;
step = 8;
mode = 1;
status = 0;
x = 0;
y = 0;
mouseflag = false;
appwidth = size().width;
appheight = size().height;
String s = null;
s = getParameter("image");
if(s == null)
{
image = null;
} else
{
image = getImage(getDocumentBase(), s);
mt = new MediaTracker(this);
mt.addImage(image, 0);
}
s = getParameter("stime");
if(s != null)
stime = Integer.valueOf(s).intValue();
s = getParameter("step");
if(s != null)
step = Integer.valueOf(s).intValue();
s = getParameter("mode");
if(s != null)
mode = Integer.valueOf(s).intValue();
nowstep = step;
offimg = createImage(appwidth, appheight);
offscr = offimg.getGraphics();
offscr.setFont(new Font("Serif", 0, 12));
setBackground(Color.lightGray);
}
//--------------------------------------------------------
public void start()
{
thread = new Thread(this);
thread.start();
}
//--------------------------------------------------------
public void stop()
{
thread.stop();
thread = null;
}
//--------------------------------------------------------
public void run()
{
if(image != null)
try
{
mt.waitForID(0);
}
catch(InterruptedException _ex) { }
do
{
try
{
Thread.currentThread();
Thread.sleep(stime);
}
catch(InterruptedException _ex) { }
repaint();
} while(true);
}
//--------------------------------------------------------
public void paint(Graphics g)
{
if(status == 0)
{
if(mt.checkID(0))
{
imgwidth = image.getWidth(this);
imgheight = image.getHeight(this);
if(mode == 3)
status = 6;
else
status = 1;
}
offscr.setColor(Color.lightGray);
offscr.fillRect(0, 0, appwidth, appheight);
offscr.setColor(Color.black);
offscr.drawString("Loading image", 10, 20);
} else
{
offscr.drawImage(image, x, y, this);
if(x < -(imgwidth - appwidth))
offscr.drawImage(image, imgwidth + x, y, this);
if(y < -(imgheight - appheight))
offscr.drawImage(image, x, imgheight + y, this);
}
g.drawImage(offimg, 0, 0, this);
if(mouseflag)
showStatus("Panorama 1.1" + lookto());
}
//--------------------------------------------------------
public void update(Graphics g)
{
switch(status)
{
case 0: // '\0'
paint(g);
return;
case 1: // '\001'
x = x - nowstep;
switch(mode)
{
default:
break;
case 0: // '\0'
case 3: // '\003'
if(x <= -imgwidth + appwidth)
{
x = -imgwidth + appwidth;
status = 4;
}
break;
case 1: // '\001'
if(x <= -imgwidth + appwidth)
{
x = -imgwidth + appwidth;
status = 2;
}
break;
case 2: // '\002'
if(x <= -imgwidth)
x = 0;
break;
}
paint(g);
return;
case 2: // '\002'
x = x + nowstep;
switch(mode)
{
default:
break;
case 0: // '\0'
case 3: // '\003'
if(x >= 0)
{
x = 0;
status = 5;
}
break;
case 1: // '\001'
if(x >= 0)
{
x = 0;
status = 1;
}
break;
case 2: // '\002'
if(x >= 0)
x = -imgwidth;
break;
}
paint(g);
return;
case 6: // '\006'
y = y - nowstep;
switch(mode)
{
default:
break;
case 0: // '\0'
case 2: // '\002'
if(y <= -imgheight + appheight)
{
y = -imgheight + appheight;
status = 8;
}
break;
case 1: // '\001'
if(y <= -imgheight + appheight)
{
y = -imgheight + appheight;
status = 7;
}
break;
case 3: // '\003'
if(y <= -imgheight)
y = 0;
break;
}
paint(g);
return;
case 7: // '\007'
y = y + nowstep;
switch(mode)
{
default:
break;
case 0: // '\0'
case 2: // '\002'
if(y >= 0)
{
y = 0;
status = 9;
}
break;
case 1: // '\001'
if(y >= 0)
{
y = 0;
status = 6;
}
break;
case 3: // '\003'
if(y >= 0)
y = -imgheight;
break;
}
paint(g);
return;
}
}
//--------------------------------------------------------
public boolean mouseEnter(Event event, int i, int j)
{
mouseflag = true;
showStatus("Panorama 1.1" + lookto());
return true;
}
//--------------------------------------------------------
public boolean mouseUp(Event event, int i, int j)
{
double d = i;
double d1 = j;
double d2 = appwidth;
double d3 = appheight;
int k;
if(d / d1 < d2 / d3)
{
if(d / (d3 - d1) < d2 / d3)
k = 2;
else
k = 6;
} else
if(d / (d3 - d1) < d2 / d3)
k = 7;
else
k = 1;
if(d >= d2 / 3D && d <= (d2 / 3D) * 2D && d1 >= d3 / 3D && d1 <= (d3 / 3D) * 2D)
k = 3;
if(k == status)
{
nowstep += nowstep;
if(nowstep >= 32)
nowstep = 32;
}
if(k == 3)
nowstep = 2;
status = k;
showStatus("Panorama 1.1" + lookto());
return true;
}
//--------------------------------------------------------
public boolean mouseExit(Event event, int i, int j)
{
mouseflag = false;
showStatus("");
return true;
}
//--------------------------------------------------------
String lookto()
{
if(status == 0)
return " ... Loading image...";
if(status == 1)
return " ... See Right!";
if(status == 2)
return " ... See Left!";
if(status == 3)
return " ... Pause!";
if(status == 4)
return " ... Right End!";
if(status == 5)
return " ... Left End!";
if(status == 6)
return " ... See Down!";
if(status == 7)
return " ... See Up!";
if(status == 8)
return " ... Down End!";
if(status == 9)
return " ... Up End!";
else
return " ... Error!";
}
}
インターネットスタートページ 鈴木維一郎 石橋三重子
|
|
|
|
|
|