// ArctanX_anim101.java // // Programmed by Hideaki `ArctanX' TANABE Aug20 1996 // // Ver 1.01 import java.awt.*; import java.applet.*; public class ArctanX_anim101 extends Applet implements Runnable { Image im[] = new Image[12]; Thread kick = null; int i, j = 0; int direction = 0; // <0...left, >0...right int wait = 200; int max_image, x_value, y_value; Integer Max_image_o = new Integer(max_image); Integer X_value_o = new Integer(x_value); Integer Y_value_o = new Integer(y_value); String path_name, left_button, right_button, stop_button; Button left, right, stop; public void init() { max_image = Max_image_o.parseInt(getParameter("maximage")); x_value = X_value_o.parseInt(getParameter("xvalue")); y_value = Y_value_o.parseInt(getParameter("yvalue")); path_name = getParameter("pathname"); left_button = getParameter("leftbutton"); right_button = getParameter("rightbutton"); stop_button = getParameter("stopbutton"); // System.out.println("max_image = " + max_image); // System.out.println("x_value = " + x_value); // System.out.println("y_value = " + y_value); // System.out.println("path_name = " + path_name); // System.out.println("left_button = " + left_button); // System.out.println("right_button = " + right_button); // System.out.println("stop_button = " + stop_button); setBackground(Color.black); left = new Button(left_button); right = new Button(right_button); stop = new Button(stop_button); add(left); add(stop); add(right); for (i = 0; i <= max_image; i++) { im[i] = getImage(getDocumentBase(), path_name + i + ".gif"); } } public void start() { if (kick == null) { kick = new Thread(this); kick.start(); } } public void run() { while (true) { if (j > max_image) { j = 0; } if (j < 0) { j = max_image; } repaint(); try { Thread.sleep(wait); } catch (InterruptedException e) { } if (direction < 0) { j--; } else { j++; } } } public void paint(Graphics g) { g.drawImage(im[j], x_value, y_value, this); } public void stop() { if (kick != null) { kick.stop(); kick = null; } } public boolean action(Event e, Object o) { String label = o.toString(); if (e.target instanceof Button) { if (label.equals(left_button)) { // System.out.println("You pushed " + left_button); direction--; // System.out.println("direction = " + direction); if (direction == 0) { kick.suspend(); } else { if (direction > 0) { wait += 20; } else { wait -= 20; if (wait < 20) { wait = 20; } } // System.out.println("wait = " + wait); kick.resume(); } } else if (label.equals(right_button)) { // System.out.println("You pushed " + right_button); direction++; // System.out.println("direction = " + direction); if (direction == 0) { kick.suspend(); } else { if (direction < 0) { wait += 20; } else { wait -= 20; if (wait < 20) { wait = 20; } } // System.out.println("wait = " + wait); kick.resume(); } } else if (label.equals(stop_button)) { // System.out.println("You pushed " + stop_button); kick.suspend(); } } return true; } }