// Free Directionally Scrolling Image 1 by Hiroyuki Murata import java.awt.*; import java.applet.Applet; public class ScrollImage1 extends Applet implements Runnable{ Thread thread=null; MediaTracker tracker; boolean loaded; static final int Width=288,Height=192,StrSu=6; static final double Speed=5.0,Rot=0.003; double direction,fx,fy; int x,y; Image imagefile,ioff; Graphics goff; String loadMsg = "Now Loading"; String fixMsg1 = "ScrollImage1"; String fixMsg2 = "faichan@kt.rim.or.jp"; Font loadFont = new Font("TimesRoman",Font.ITALIC,40); Font fixFont = new Font("TimesRoman",Font.BOLD,20); FontMetrics fixMetrics; int fixX1,fixY1,fixX2,fixY2; public void init(){ resize(Width,Height); tracker = new MediaTracker(this); imagefile = getImage(getDocumentBase(), "images/a010-32.jpg"); tracker.addImage(imagefile, 0); loaded = false; direction = (double)(Math.PI/4.0); fx = fy = 0.0; ioff = createImage(Width,Height*2); goff = ioff.getGraphics(); goff.setColor(Color.white); goff.fillRect(0,0,Width,Height*2); goff.setFont(loadFont); goff.setColor(Color.blue); goff.drawString(loadMsg,10,Height*3/2); goff.setFont(fixFont); goff.setColor(Color.white); fixMetrics = getFontMetrics(fixFont); fixX1 = 10; fixY1 = Height + fixMetrics.getAscent() + 3; fixX2 = Width - fixMetrics.stringWidth(fixMsg2) - 10; fixY2 = Height * 2 - fixMetrics.getDescent() - 3; } public void start(){ if(thread == null){ thread = new Thread(this); thread.start(); } } public void stop(){ if(thread != null){ thread.stop(); thread = null; } } public void run(){ if(!loaded){ try { tracker.waitForAll(); } catch (InterruptedException e) { return; } goff.drawImage(imagefile,0,0,this); loaded = true; } while(thread.isAlive()){ try{ thread.sleep(50); } catch(InterruptedException e){ break; } repaint(); } } //----------------------------------------------------------- public void update(Graphics g){ goff.copyArea(0,0, x,y, Width-x,Height*2-y ); goff.copyArea(x,0, Width-x,y, -x,Height*2-y ); goff.copyArea(0,y, x,Height-y, Width-x,Height-y ); goff.copyArea(x,y, Width-x,Height-y, -x,Height-y ); goff.drawString(fixMsg1, fixX1,fixY1); goff.drawString(fixMsg2, fixX2,fixY2); paint(g); direction += Rot; if(direction>(double)(Math.PI*2)) direction -= (double)(Math.PI*2); fx += Speed * Math.sin(direction); fy += Speed * Math.cos(direction); if(fx<0) fx += Width; else if(fx>=Width) fx -= Width; if(fy<0) fy += Height; else if(fy>=Height) fy -= Height; x = (int)fx; y = (int)fy; } public void paint(Graphics g){ g.drawImage(ioff,0,-Height,this); } }