import java.awt.*; public class Pan2 extends javax.swing.JApplet implements Runnable { Thread runner; Image back, fore, workspace; Graphics offscreen; String text; String fontName; int direction = 1; int fontSize = 24; int x1 = 0; int x2; public void init() { workspace = createImage(getSize().width, getSize().height); offscreen = workspace.getGraphics(); // get parameters String imageBack = getParameter("background"); if (imageBack != null) back = getImage(getDocumentBase(), imageBack); String imageFore = getParameter("foreground"); if (imageFore != null) fore = getImage(getDocumentBase(), imageFore); x2 = getSize().width; text = getParameter("text"); fontName = getParameter("font"); if (fontName == null) fontName = "Arial"; String param = getParameter("fontsize"); if (param != null) fontSize = Integer.parseInt("0" + param); String dirParam = getParameter("direction"); if (dirParam.equals("left")) direction = 1; else direction = -1; } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner = null; } } public void run() { Thread thisThread = Thread.currentThread(); while (runner == thisThread) { repaint(); try { Thread.sleep(200); } catch (InterruptedException e) {} x1 = x1 - direction; x2 = x2 - direction; if (direction == 1) { if (x1 <= (getSize().width * -1)) x1 = getSize().width; if (x2 <= (getSize().width * -1)) x2 = getSize().width; } else { if (x1 >= getSize().width) x1 = getSize().width * -1; if (x2 >= getSize().width) x2 = getSize().width * -1; } } } public void paint(Graphics screen) { Graphics2D screen2D = (Graphics2D) screen; offscreen.drawImage(back, x1, 0, null); offscreen.drawImage(back, x2, 0, null); if (fore != null) offscreen.drawImage(fore, 0, 0, null); if (text != null) { offscreen.setColor(Color.black); Font f = new Font(fontName, Font.BOLD, fontSize); FontMetrics fm = getFontMetrics(f); offscreen.setFont(f); int xStart = (getSize().width - fm.stringWidth(text)) / 2; int yStart = getSize().height/2 + fm.getHeight()/4; offscreen.drawString(text, xStart, yStart); offscreen.setColor(Color.white); offscreen.drawString(text, xStart-2, yStart-2); } screen2D.drawImage(workspace, 0, 0, this); } public void update(Graphics screen) { paint(screen); } }