authorauthorversion
import java.awt.*;
import java.awt.event.*;
public class Panorama extends java.applet.Applet
implements Runnable, MouseListener {
Image img, buf;
MediaTracker mt;
int iw, ih;
int shift = 10;
Graphics bufg, bufb;
Thread t;
boolean userPause = false;
public void init() {
String imgName = getParameter("image"); if (imgName==null) imgName = "Panorama.gif";
img = getImage(getDocumentBase(),imgName);
mt = new MediaTracker(this);
mt.addImage(img,0);
try {
mt.waitForAll();
} catch(InterruptedException e) {
e.printStackTrace();
}
iw = img.getWidth(null);
ih = img.getHeight(null);
buf = createImage(iw+Math.abs(shift),ih);
bufg = buf.getGraphics();
bufg.drawImage(img, 0, 0 ,null);
int ch = 60;
int cw = ch;
int cx = 300;
int cy = 0;
int eh = ch/5;
int ew = eh;
int as = 225;
int aa = 90;
bufg.setColor(Color.green);
bufg.drawOval(cx-cw/2, cy+ch/2, ch, cw);
bufg.fillOval(cx-cw/4-ew/2, cy+ch/2+eh, eh, ew);
bufg.fillOval(cx+cw/4-ew/2, cy+ch/2+eh, eh, ew);
bufg.drawArc(cx-3*cw/8, cy+5*ch/8, 3*ch/4, 3*cw/4, as, aa);
addMouseListener(this);
}
public void start() {
t = new Thread(this);
t.start();
}
public void paint(Graphics g) {
g.drawImage(buf, 0, 0, null);
}
public void advance() {
if (shift > 0) {
bufg.copyArea(0, 0, iw, ih, shift, 0);
bufg.copyArea(iw, 0, shift, ih, -iw, 0);
} else {
bufg.copyArea(0, 0, Math.abs(shift), ih, iw, 0);
bufg.copyArea(Math.abs(shift), 0, iw, ih, -Math.abs(shift), 0);
}
}
public void run() {
while(true) {
advance();
repaint();
try {
Thread.sleep(33);
} catch(InterruptedException e) {
e.printStackTrace();
return;
}
}
}
public String getAppletInfo() {
String info = "Title: Panorama\n";
info = info + "Description: Produces a scrolling panoramic view\n";
info = info + "Author: Mark Crocker (http://www.markcrocker.com/~mcrocker)\n";
info = info + "Derived from lessons in IBM's Java Applet Workshop";
info = info + "(http://www.ibm.com/java/education/buildapplet/)";
return info;
}
public String[][] getParameterInfo() {
String pinfo[][] = {
{"dummy", "n/a", "no paramters used by this applet"},
};
return pinfo;
}
public void update(Graphics g) {
paint(g);
}
public void stop() {
t.stop();
t = null;
}
public void destroy() {
}
public void mousePressed(MouseEvent event) {
if (userPause) {
t.resume();
shift = -shift;
} else {
t.suspend();
}
userPause = !userPause;
}
public void mouseClicked(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
}