//******************************************************************************** // Panorama.java // // Java 1.1 // // (c) 2000 Maeda Mameo http://hw001.gate01.com/frog/ //******************************************************************************** import java.applet.Applet; import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.image.ImageObserver; //******************************************************************************** public class Panorama extends Applet implements Runnable, MouseListener, MouseMotionListener{ private int theWidth, theHeight, argWidth, argHeight, mouseX, mouseY; private Image imageOff, argImage; private Graphics gOff; private Thread theThread; //******************************************************************************** public void init(){ Dimension d; argHeight = 0; mouseY = -1; d = getSize(); theWidth = d.width; theHeight = d.height; imageOff = createImage( theWidth, theHeight); gOff = imageOff.getGraphics(); argImage = getImage( getDocumentBase(), getParameter( "image")); if( prepareImage( argImage, this)){ argWidth = argImage.getWidth( this); argHeight = argImage.getHeight( this); } addMouseListener( this); addMouseMotionListener( this); } public void start(){ theThread = new Thread( this); theThread.start();} public void stop(){ theThread.stop(); theThread = null;} public void update( Graphics g){ paint( g);} public void paint( Graphics g){ g.drawImage( imageOff, 0, 0, this);} public boolean imageUpdate( Image img, int infoflags, int x, int y, int width, int height){ if( img == argImage && ( infoflags & ImageObserver.ALLBITS) != 0){ argWidth = argImage.getWidth( this); argHeight = argImage.getHeight( this); return false; } return true; } public void mouseClicked( MouseEvent e){} public void mouseEntered( MouseEvent e){ mouseX = e.getX(); mouseY = e.getY();} public void mouseExited( MouseEvent e){ mouseY = -1;} public void mousePressed( MouseEvent e){} public void mouseReleased( MouseEvent e){} public void mouseMoved( MouseEvent e){ mouseX = e.getX(); mouseY = e.getY();} public void mouseDragged( MouseEvent e){} //******************************************************************************** public void run(){ int x, y, peepX, peepY, vx; String s; FontMetrics fm; s = "loading..."; fm = gOff.getFontMetrics(); x = ( theWidth - fm.stringWidth( s)) / 2; y = ( theHeight + fm.getMaxAscent()) / 2; while( argHeight == 0){ gOff.setColor( Color.gray); gOff.fillRect( 0, 0, theWidth, theHeight); repaint(); sleeper( 200); gOff.setColor( Color.black); gOff.drawString( s, x, y); repaint(); sleeper( 300); } peepX = peepY = vx = 0; while( true){ if( 0 <= mouseY){ vx = ( 1200 * mouseX / theWidth - 600); peepY += ( 1200 * mouseY / theHeight - 600); } else{ if( vx < 300) vx += 3; else vx -= 3; } peepX += vx; if( peepX < 0) peepX += argWidth * 100; if( argWidth * 100 <= peepX) peepX -= argWidth * 100; if( peepY < 0) peepY = 0; if( ( argHeight - theHeight) * 100 < peepY) peepY = ( argHeight - theHeight) * 100; x = peepX / 100; y = peepY / 100; if( x < argWidth - theWidth) gOff.drawImage( argImage, 0, 0, theWidth, theHeight, x, y, x + theWidth, y + theHeight, Color.gray, this); else{ gOff.drawImage( argImage, 0, 0, argWidth - x, theHeight, x, y, argWidth, y + theHeight, Color.gray, this); gOff.drawImage( argImage, argWidth - x, 0, theWidth, theHeight, 0, y, theWidth - argWidth + x, y + theHeight, Color.gray, this); } repaint(); sleeper( 20); } } //******************************************************************************** private void sleeper( long t){ try{ Thread.sleep( t);} catch( InterruptedException e){};} //******************************************************************************** }