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.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.image.ImageObserver;
-
- public class snaketext extends Applet implements Runnable {
- private char[] separated;
- private int stringLength;
- private Thread engine;
- private boolean userPause;
- private int x_coord;
- private int y_coord;
- private int cur_x;
- private int cur_y;
- private int stepx = 10;
- private int stepy = 1;
- private int sleepTime;
- private boolean threadSuspended;
- private boolean debug;
- private myFont font;
- private int fontsize = 20;
- private int fontstyle;
- // $FF: renamed from: up boolean
- private boolean field_0 = true;
- private boolean ascend = true;
- private boolean forward;
- private boolean dir_right = true;
- private Color foreGroundColor;
- private Color backGroundColor;
- private Image offScrImage;
- private Graphics offScrGraphics;
- private Dimension offScrSize;
- private boolean matched;
- private boolean unreg = true;
-
- public void stop() {
- if (this.engine != null && this.engine.isAlive()) {
- this.engine.stop();
- }
-
- this.engine = null;
- }
-
- private synchronized void detecter(int var1, int var2, int var3) {
- this.x_coord = this.forward ? this.x_coord - var1 : this.x_coord + var1;
- this.y_coord = this.field_0 ? this.y_coord - this.stepy : this.y_coord + this.stepy;
- if (this.y_coord <= 0 + var3) {
- this.field_0 = false;
- this.y_coord += this.stepy;
- } else if (this.y_coord >= ((Component)this).size().height) {
- this.field_0 = true;
- this.y_coord -= this.stepy;
- }
-
- if (this.x_coord <= 0) {
- this.forward = false;
- this.x_coord = 0 - this.x_coord;
- } else if (this.x_coord + var2 >= ((Component)this).size().width) {
- this.forward = true;
- this.x_coord = ((Component)this).size().width - (var2 + (this.x_coord + var2 - ((Component)this).size().width));
- }
-
- }
-
- public void paint(Graphics var1) {
- var1.setColor(this.backGroundColor);
- var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- var1.setFont(this.font);
- var1.setColor(this.foreGroundColor);
- FontMetrics var2 = var1.getFontMetrics();
-
- for(int var3 = 0; var3 < this.stringLength; ++var3) {
- var1.drawChars(this.separated, var3, 1, this.x_coord, this.y_coord);
- if (!this.forward) {
- if (var3 < this.stringLength - 1) {
- this.detecter(var2.charsWidth(this.separated, var3, 1), var2.charsWidth(this.separated, var3 + 1, 1), var2.getAscent());
- } else {
- this.detecter(var2.charsWidth(this.separated, var3, 1), 0, var2.getAscent());
- }
- } else if (var3 < this.stringLength - 1) {
- this.detecter(var2.charsWidth(this.separated, var3 + 1, 1), 0, var2.getAscent());
- }
- }
-
- this.cur_x = this.dir_right ? this.cur_x + this.stepx : this.cur_x - this.stepx;
- int var4 = var2.charsWidth(this.separated, 0, 1);
- if (this.dir_right && this.cur_x + var4 >= ((Component)this).size().width) {
- this.dir_right = false;
- this.cur_x = ((Component)this).size().width - (var4 + (this.cur_x + var4 - ((Component)this).size().width));
- } else if (this.cur_x <= 0) {
- this.dir_right = true;
- this.cur_x = 0 - this.cur_x;
- }
-
- if (this.y_coord <= 0) {
- this.field_0 = false;
- } else if (this.y_coord >= ((Component)this).size().height) {
- this.field_0 = true;
- }
-
- this.forward = !this.dir_right;
- this.x_coord = this.cur_x;
- }
-
- private void dbg(String var1) {
- if (this.debug) {
- System.out.println(var1);
- }
-
- }
-
- public synchronized void update(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- if (this.offScrImage == null || var2.width != this.offScrSize.width || var2.height != this.offScrSize.height) {
- this.offScrImage = ((Component)this).createImage(var2.width, var2.height);
- this.offScrGraphics = this.offScrImage.getGraphics();
- this.offScrGraphics.setFont(((Component)this).getFont());
- this.offScrSize = var2;
- }
-
- this.offScrGraphics.fillRect(0, 0, var2.width, var2.height);
- this.paint(this.offScrGraphics);
- var1.drawImage(this.offScrImage, 0, 0, (ImageObserver)null);
- }
-
- public void start() {
- if (this.engine == null) {
- this.engine = new Thread(this);
- }
-
- this.engine.start();
- }
-
- public String getAppletInfo() {
- return "snaketext.class v1.1 Copyright Sausage SoftWare 1996";
- }
-
- public void run() {
- this.dbg("entered run");
- Thread.currentThread().setPriority(1);
-
- while(true) {
- if (this.unreg) {
- ((Applet)this).getAppletContext().showStatus("Unregistered version. Copyright (c) Sausage Software 1996");
- }
-
- ((Component)this).repaint();
-
- try {
- Thread.sleep((long)this.sleepTime);
- } catch (Exception var1) {
- }
- }
- }
-
- public void init() {
- String var1 = ((Applet)this).getParameter("font");
- Object var2 = null;
- String var14 = myFont.getFontName(var1);
- this.dbg(var14);
- var1 = ((Applet)this).getParameter("fontsize");
- if (var1 != null) {
- this.fontsize = Integer.parseInt(var1);
- }
-
- var1 = ((Applet)this).getParameter("style");
- this.fontstyle = myFont.getFontStyle(var1);
- this.font = new myFont(var14, this.fontstyle, this.fontsize);
- var1 = ((Applet)this).getParameter("color");
- if (var1 != null) {
- createColor var3 = new createColor(var1, ",");
- this.foreGroundColor = var3.getColor();
- } else {
- this.foreGroundColor = new Color(255, 0, 0);
- }
-
- var1 = ((Applet)this).getParameter("background");
- if (var1 != null) {
- createColor var15 = new createColor(var1, ",");
- this.backGroundColor = var15.getColor();
- } else {
- this.backGroundColor = new Color(0, 0, 0);
- }
-
- String var16 = ((Applet)this).getParameter("text");
- if (var16 == null) {
- var16 = "Sausage Software";
- }
-
- this.stringLength = var16.length();
- String var4 = ((Applet)this).getParameter("reguser");
- if (var4 == null) {
- ver.NotRegistered();
- }
-
- if (var4.toLowerCase().equals("unregistered")) {
- this.unreg = true;
- } else {
- this.unreg = false;
- }
-
- String var5 = ((Applet)this).getParameter("serialid");
- if (var5 == null) {
- ver.NotRegistered();
- }
-
- ver var6 = new ver(var4, var5);
- this.matched = var6.verifyUser(var16);
- if (!this.matched) {
- ver.NotRegistered();
- }
-
- var1 = ((Applet)this).getParameter("horizontal");
- if (var1 != null) {
- this.stepx = Integer.valueOf(var1);
- }
-
- var1 = ((Applet)this).getParameter("vertical");
- if (var1 != null) {
- this.stepy = Integer.valueOf(var1);
- }
-
- var1 = ((Applet)this).getParameter("speed");
- if (var1 != null) {
- this.sleepTime = Integer.parseInt(var1);
- }
-
- this.separated = new char[this.stringLength];
- var16.getChars(0, var16.length(), this.separated, 0);
- this.x_coord = this.cur_x = 0;
- this.y_coord = this.cur_y = ((Component)this).size().height;
- this.dbg("finish init");
- }
-
- public boolean handleEvent(Event var1) {
- if (var1.id == 501) {
- if (this.userPause) {
- this.engine.resume();
- } else {
- this.engine.suspend();
- }
-
- this.userPause = !this.userPause;
- }
-
- return true;
- }
- }
-