home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.image.ImageObserver;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.StringTokenizer;
-
- public class DancingText extends Applet implements Runnable {
- StringInfo strInfo = new StringInfo();
- ColorInfo color = new ColorInfo();
- Image offscreen;
- Graphics offgraphics;
- Thread myThread;
- Font font;
- boolean shadow;
- boolean mouse;
- int charSpace;
- int maxXOff;
- int maxYOff;
- int shaXOff;
- int shaYOff;
- int speed;
- URL url;
- Dimension dim;
- String target;
-
- public void init() {
- int var2 = 0;
- String var1;
- if ((var1 = ((Applet)this).getParameter("fontStyle")) != null) {
- StringTokenizer var3 = new StringTokenizer(var1, "|");
-
- while(var3.hasMoreTokens()) {
- String var4 = var3.nextToken();
- if (var4.equals("PLAIN")) {
- var2 += 0;
- } else if (var4.equals("BOLD")) {
- ++var2;
- } else if (var4.equals("ITALIC")) {
- var2 += 2;
- }
- }
- } else {
- var2 = 0;
- }
-
- int var21;
- if ((var1 = ((Applet)this).getParameter("fontSize")) != null) {
- var21 = Integer.parseInt(var1);
- } else {
- var21 = 36;
- }
-
- String var22;
- if ((var1 = ((Applet)this).getParameter("fontName")) != null) {
- var22 = var1;
- } else {
- var22 = "TimesRoman";
- }
-
- this.font = new Font(var22, var2, var21);
- if ((var1 = ((Applet)this).getParameter("charSpace")) != null) {
- this.charSpace = Integer.parseInt(var1);
- } else {
- this.charSpace = 2;
- }
-
- if ((var1 = ((Applet)this).getParameter("maxXOffset")) != null) {
- this.maxXOff = Integer.parseInt(var1);
- } else {
- this.maxXOff = 2;
- }
-
- if ((var1 = ((Applet)this).getParameter("maxYOffset")) != null) {
- this.maxYOff = Integer.parseInt(var1);
- } else {
- this.maxYOff = 4;
- }
-
- if ((var1 = ((Applet)this).getParameter("shadowXOffset")) != null) {
- this.shaXOff = Integer.parseInt(var1);
- } else {
- this.shaXOff = 3;
- }
-
- if ((var1 = ((Applet)this).getParameter("shadowYOffset")) != null) {
- this.shaYOff = Integer.parseInt(var1);
- } else {
- this.shaYOff = 3;
- }
-
- if ((var1 = ((Applet)this).getParameter("text")) == null) {
- var1 = "DancingText";
- }
-
- this.strInfo.putInfo(var1, this.font, this.charSpace, this.maxXOff + Math.abs(this.shaXOff), this.maxYOff + Math.abs(this.shaYOff));
- ((Applet)this).resize(this.strInfo.width, this.strInfo.height);
- if ((var1 = ((Applet)this).getParameter("shadow")) != null) {
- this.shadow = new Boolean(var1);
- } else {
- this.shadow = true;
- }
-
- if (this.shadow && (var1 = ((Applet)this).getParameter("shadowColor")) != null) {
- this.color.shadowColor = this.color.getColor(var1);
- } else {
- this.color.shadowColor = new Color(128, 128, 128);
- }
-
- var1 = ((Applet)this).getParameter("textColor");
- this.color.calcColor(var1, this.strInfo.length);
- if ((var1 = ((Applet)this).getParameter("baseColor")) != null) {
- this.color.baseColor = this.color.getColor(var1);
- } else {
- this.color.baseColor = ((Component)this).getBackground();
- }
-
- if ((var1 = ((Applet)this).getParameter("speed")) != null) {
- this.speed = Integer.parseInt(var1);
- } else {
- this.speed = 100;
- }
-
- if ((var1 = ((Applet)this).getParameter("target")) != null) {
- this.target = var1;
- }
-
- if ((var1 = ((Applet)this).getParameter("URL")) != null) {
- try {
- this.url = new URL(var1);
- } catch (MalformedURLException var5) {
- System.out.println("Malformed URL: Check Applet parameter - URL");
- }
- }
-
- this.dim = ((Component)this).size();
- this.offscreen = ((Component)this).createImage(this.dim.width, this.dim.height);
- this.offgraphics = this.offscreen.getGraphics();
- this.offgraphics.setFont(this.font);
- }
-
- public void start() {
- if (this.myThread == null) {
- this.myThread = new Thread(this);
- this.myThread.start();
- }
-
- }
-
- public void stop() {
- this.myThread.stop();
- this.myThread = null;
- }
-
- public void run() {
- for(; this.myThread != null; ((Component)this).repaint()) {
- try {
- Thread.sleep((long)this.speed);
- } catch (InterruptedException var1) {
- }
- }
-
- }
-
- public void update(Graphics var1) {
- this.offgraphics.setColor(this.color.baseColor);
- this.offgraphics.fillRect(0, 0, this.dim.width, this.dim.height);
- int var2 = this.shaXOff < 0 ? -this.shaXOff + 4 : 4;
- int var3 = 1 + this.strInfo.ascent - (this.shaYOff < 0 ? this.shaYOff : 0);
-
- for(int var4 = 0; var4 < this.strInfo.length; ++var4) {
- int var5 = var2 + (int)(Math.random() * (double)this.maxXOff);
- int var6 = var3 + (int)(Math.random() * (double)this.maxYOff);
- if (this.shadow) {
- this.offgraphics.setColor(this.color.shadowColor);
- this.offgraphics.drawChars(this.strInfo.separated, var4, 1, var5 + this.shaXOff, var6 + this.shaYOff);
- }
-
- this.offgraphics.setColor(this.color.textColor[var4]);
- this.offgraphics.drawChars(this.strInfo.separated, var4, 1, var5, var6);
- var2 += this.strInfo.charWidth[var4];
- }
-
- var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
- }
-
- public void paint(Graphics var1) {
- var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- if (this.url != null) {
- ((Applet)this).showStatus(this.url.toString());
- }
-
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- if (this.url != null) {
- ((Applet)this).showStatus("");
- }
-
- return true;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.url != null) {
- if (this.target != null) {
- ((Applet)this).getAppletContext().showDocument(this.url, this.target);
- } else {
- ((Applet)this).getAppletContext().showDocument(this.url);
- }
-
- ((Applet)this).showStatus("Opening document, please wait.");
- }
-
- return true;
- }
-
- public String getAppletInfo() {
- return "DancingText 1.0 by Stanley Poon - 12 Feb 1996";
- }
- }
-