home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Image;
- import java.awt.LayoutManager;
- import java.awt.Panel;
-
- public class Wobble extends Applet implements Runnable {
- WobbleCanvas wobbler;
- Thread animatorThread;
- boolean frozen = false;
- int moveAdd = 1;
-
- public void init() {
- super.init();
- ((Container)this).setLayout((LayoutManager)null);
- ((Panel)this).addNotify();
- int color = 0;
- String paraString = ((Applet)this).getParameter("COLOR");
- if (paraString != null) {
- try {
- color = Integer.parseInt(paraString, 16);
- } catch (NumberFormatException var7) {
- }
- }
-
- Image image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("SRC"));
- this.wobbler = new WobbleCanvas(image, color);
- paraString = ((Applet)this).getParameter("AMPLIFY");
- if (paraString != null) {
- try {
- this.wobbler.setAmplitude((double)Integer.parseInt(paraString));
- } catch (NumberFormatException var6) {
- }
- }
-
- paraString = ((Applet)this).getParameter("BASE");
- if (paraString != null) {
- try {
- this.wobbler.setBaseline(Integer.parseInt(paraString));
- } catch (NumberFormatException var5) {
- }
- }
-
- paraString = ((Applet)this).getParameter("MOVE");
- if (paraString != null) {
- try {
- this.moveAdd = Integer.parseInt(paraString);
- } catch (NumberFormatException var4) {
- }
- }
-
- ((Container)this).add(this.wobbler);
- }
-
- public String getAppletInfo() {
- return "Wobble by Marcus Schiesser";
- }
-
- public void start() {
- if (!this.frozen) {
- if (this.animatorThread == null) {
- this.animatorThread = new Thread(this);
- }
-
- this.animatorThread.start();
- }
-
- }
-
- public void stop() {
- this.animatorThread = null;
- }
-
- public boolean mouseDown(Event e, int x, int y) {
- if (this.frozen) {
- this.frozen = false;
- this.start();
- } else {
- this.frozen = true;
- this.stop();
- }
-
- return true;
- }
-
- public boolean handleEvent(Event event) {
- return super.handleEvent(event);
- }
-
- public void run() {
- Thread.currentThread().setPriority(1);
- long startTime = System.currentTimeMillis();
-
- while(Thread.currentThread() == this.animatorThread) {
- this.wobbler.moveDelta(this.moveAdd);
- this.wobbler.repaint();
-
- try {
- startTime += 50L;
- Thread.sleep(Math.max(0L, startTime - System.currentTimeMillis()));
- } catch (InterruptedException var3) {
- return;
- }
- }
-
- }
- }
-