import java.applet.*; import java.awt.*; import utilities.*; public class JarApplet extends Applet implements Runnable, Extra { protected final static String text = "I'm Free!"; protected Thread self; // applet body runs as a seperate thread protected int width, height; // applet dimensions on page protected int textX, x; //------------------------------------------------------------------- // Applet initializer //------------------------------------------------------------------- public void init() { width = getBounds().width; height = getBounds().height; setFont(new Font("Roman", Font.BOLD, 32)); FontMetrics fm = getGraphics().getFontMetrics(); width -= fm.stringWidth(text); textX = 0; } //------------------------------------------------------------------- // The applet's core logic is located in a seperate thread so that // start/stop can control us. //------------------------------------------------------------------- public void run() { while ( self != null ) { textX += 2; textX %= width * 2; x = (textX > width) ? (width*2 - textX) : textX; repaint(); MiscKit.delay(50); } } //------------------------------------------------------------------- // Draw a large string bouncing horizontally // Note that we do not override update() so the Canvas will be cleared // before each paint(). //------------------------------------------------------------------- public void paint(Graphics g) { g.drawString(text, x, height/2+8); } //------------------------------------------------------------------- // Every applet should override getAppletInfo() and getParameterInfo() // so that browsers can print some sensible information on applet. //------------------------------------------------------------------- public String getAppletInfo() { StringBuffer s = new StringBuffer(); s.append("JarApplet\n"); s.append((char) 169); // Copyright symbol s.append("1997 L. Vanhelsuwe, All Rights Reserved\n"); return s.toString(); } public String[][] getParameterInfo() { String[][] parameterInfo = { }; return parameterInfo; } //------------------------------------------------------------------- // the applet's start/stop methods. Here we control the applet thread //------------------------------------------------------------------- public void start() { if (self == null) { self = new Thread(this); self.start(); } } public void stop() { if (self != null) { self.stop(); self = null; } } } // End of Class JarApplet