home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class MORPHTEA extends Applet implements Runnable {
- Thread m_MORPHTEA;
- private Graphics m_Graphics;
- private Image[] m_Images;
- private int m_nCurrImage;
- private int m_nImgWidth;
- private int m_nImgHeight;
- private boolean m_fAllLoaded;
- private int m_nDelay = 50;
- private int m_nOffset = 15;
- private Button m_PrevButton = new Button("Prev");
- private Button m_NextButton = new Button("Next");
- private Button m_playButton = new Button("Play");
- private String m_sbuttonStatus = "Play";
- private int m_frps = 20;
- private String m_imageFile = "";
- private String m_imageType = "jpg";
- private int m_numImages = 16;
- private Color m_backgroundColor;
- private String m_sOrder;
- private String m_sShowButtons;
- private final String PARAM_frps;
- private final String PARAM_imageFile;
- private final String PARAM_imageType;
- private final String PARAM_numImages;
- private final String PARAM_backgroundColor;
- private final String PARAM_imageOrder;
- private final String PARAM_showButtons;
-
- public boolean mouseMove(Event evt, int x, int y) {
- this.m_nDelay = 1000 / (x * 50 / ((Component)this).size().width + 1);
- return true;
- }
-
- public void stop() {
- if (this.m_MORPHTEA != null) {
- this.m_MORPHTEA.stop();
- this.m_MORPHTEA = null;
- }
-
- }
-
- public boolean mouseEnter(Event evt, int x, int y) {
- return true;
- }
-
- public boolean mouseExit(Event evt, int x, int y) {
- this.m_nDelay = 1000 / this.m_frps;
- return true;
- }
-
- public void paint(Graphics g) {
- if (this.m_fAllLoaded) {
- Rectangle r = g.getClipRect();
- g.clearRect(r.x, r.y, r.width, r.height);
- this.displayImage(g);
- } else {
- g.drawString("Loading images...", 10, 40);
- }
-
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- return true;
- }
-
- public String[][] getParameterInfo() {
- String[][] info = new String[][]{{"frps", "int", "Frames pr second"}, {"imageFile", "String", "Image Files"}, {"imageType", "String", "Image Type"}, {"numImages", "int", "Number of Images"}, {"backgroundColor", "Color", "Background Color"}, {"imageOrder", "String", "Image Order"}, {"showButtons", "String", "Show Buttons"}};
- return info;
- }
-
- public void destroy() {
- }
-
- private void displayImage(Graphics g) {
- if (this.m_fAllLoaded) {
- if (this.m_sOrder.compareTo("circular") != 0 && this.m_sOrder.compareTo("linear") != 0) {
- g.drawImage(this.m_Images[(int)(Math.random() * (double)this.m_numImages)], (((Component)this).size().width - this.m_nImgWidth) / 2, (((Component)this).size().height - this.m_nImgHeight) / 2, (ImageObserver)null);
- } else if (this.m_nCurrImage >= this.m_numImages && this.m_sOrder.compareTo("linear") != 0) {
- g.drawImage(this.m_Images[2 * this.m_numImages - 2 - this.m_nCurrImage], (((Component)this).size().width - this.m_nImgWidth) / 2, (((Component)this).size().height - this.m_nImgHeight) / 2 + this.m_nOffset, (ImageObserver)null);
- } else {
- g.drawImage(this.m_Images[this.m_nCurrImage], (((Component)this).size().width - this.m_nImgWidth) / 2, (((Component)this).size().height - this.m_nImgHeight) / 2 + this.m_nOffset, (ImageObserver)null);
- }
-
- }
- }
-
- public void start() {
- if (this.m_MORPHTEA == null) {
- this.m_MORPHTEA = new Thread(this);
- this.m_MORPHTEA.start();
- }
-
- }
-
- public String getAppletInfo() {
- return "Name: MORPHTEA\r\n" + "Author: Jim Andrews (jandrews@islandnet.com)";
- }
-
- public boolean action(Event event, Object obj) {
- Object oTarget = event.target;
- if (!(oTarget instanceof Button)) {
- return false;
- } else {
- Button buttonTarget = (Button)oTarget;
- String sButtonString = buttonTarget.getLabel();
- if (sButtonString.compareTo("Prev") == 0) {
- if (this.m_sbuttonStatus != "Play") {
- this.m_nCurrImage += -1;
- if (this.m_nCurrImage == -1) {
- this.m_nCurrImage = 0;
- }
- }
-
- this.m_sbuttonStatus = "Prev";
- return true;
- } else if (sButtonString.compareTo("Next") != 0) {
- if (sButtonString.compareTo("Play") == 0) {
- this.m_sbuttonStatus = "Play";
- return true;
- } else {
- return false;
- }
- } else {
- if (this.m_sbuttonStatus != "Play") {
- ++this.m_nCurrImage;
- if (this.m_nCurrImage > 2 * this.m_numImages - 3 && this.m_sOrder.compareTo("circular") == 0) {
- this.m_nCurrImage = 2 * this.m_numImages - 3;
- } else if (this.m_sOrder.compareTo("linear") == 0 && this.m_nCurrImage > this.m_numImages - 1) {
- this.m_nCurrImage = 0;
- }
- }
-
- this.m_sbuttonStatus = "Next";
- return true;
- }
- }
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- return true;
- }
-
- public void run() {
- this.m_nCurrImage = 0;
- if (!this.m_fAllLoaded) {
- ((Component)this).repaint();
- this.m_Graphics = ((Component)this).getGraphics();
- this.m_Images = new Image[this.m_numImages];
- MediaTracker tracker = new MediaTracker(this);
-
- for(int i = 0; i < this.m_numImages; ++i) {
- String strImage = this.m_imageFile + (i < 10 ? "0" : "") + i + "." + this.m_imageType;
- this.m_Images[i] = ((Applet)this).getImage(((Applet)this).getDocumentBase(), strImage);
- tracker.addImage(this.m_Images[i], 0);
- }
-
- try {
- tracker.waitForAll();
- this.m_fAllLoaded = !tracker.isErrorAny();
- } catch (InterruptedException var5) {
- }
-
- if (!this.m_fAllLoaded) {
- this.stop();
- this.m_Graphics.drawString("Error loading images!", 10, 40);
- return;
- }
-
- this.m_nImgWidth = this.m_Images[0].getWidth(this);
- this.m_nImgHeight = this.m_Images[0].getHeight(this);
- }
-
- ((Component)this).repaint();
-
- while(true) {
- try {
- this.displayImage(this.m_Graphics);
- if (this.m_sbuttonStatus == "Play") {
- ++this.m_nCurrImage;
- }
-
- if (this.m_sOrder.compareTo("circular") == 0 && this.m_nCurrImage > 2 * this.m_numImages - 3) {
- this.m_nCurrImage = 0;
- } else if (this.m_nCurrImage > this.m_numImages - 1 && this.m_sOrder.compareTo("linear") == 0) {
- this.m_nCurrImage = 0;
- }
-
- Thread.sleep((long)this.m_nDelay);
- } catch (InterruptedException var6) {
- this.stop();
- }
- }
- }
-
- public void init() {
- String param = ((Applet)this).getParameter("frps");
- if (param != null) {
- this.m_frps = Integer.parseInt(param);
- this.m_nDelay = 1000 / this.m_frps;
- }
-
- param = ((Applet)this).getParameter("imageFile");
- if (param != null) {
- this.m_imageFile = param;
- }
-
- param = ((Applet)this).getParameter("imageType");
- if (param != null) {
- this.m_imageType = param;
- }
-
- param = ((Applet)this).getParameter("numImages");
- if (param != null) {
- this.m_numImages = Integer.parseInt(param);
- }
-
- param = ((Applet)this).getParameter("imageOrder");
- if (param != null) {
- this.m_sOrder = param;
- }
-
- param = ((Applet)this).getParameter("showButtons");
- if (param != null) {
- this.m_sShowButtons = param;
- }
-
- param = ((Applet)this).getParameter("backgroundColor");
- if (param != null) {
- if (param.compareTo("black") == 0) {
- this.m_backgroundColor = Color.black;
- } else if (param.compareTo("blue") == 0) {
- this.m_backgroundColor = Color.blue;
- } else if (param.compareTo("cyan") == 0) {
- this.m_backgroundColor = Color.cyan;
- } else if (param.compareTo("darkGray") == 0) {
- this.m_backgroundColor = Color.darkGray;
- } else if (param.compareTo("gray") == 0) {
- this.m_backgroundColor = Color.gray;
- } else if (param.compareTo("green") == 0) {
- this.m_backgroundColor = Color.green;
- } else if (param.compareTo("lightGray") == 0) {
- this.m_backgroundColor = Color.lightGray;
- } else if (param.compareTo("magenta") == 0) {
- this.m_backgroundColor = Color.magenta;
- } else if (param.compareTo("orange") == 0) {
- this.m_backgroundColor = Color.orange;
- } else if (param.compareTo("pink") == 0) {
- this.m_backgroundColor = Color.pink;
- } else if (param.compareTo("red") == 0) {
- this.m_backgroundColor = Color.red;
- } else if (param.compareTo("white") == 0) {
- this.m_backgroundColor = Color.white;
- } else if (param.compareTo("yellow") == 0) {
- this.m_backgroundColor = Color.yellow;
- } else {
- this.m_backgroundColor = Color.blue;
- }
- }
-
- ((Component)this).setBackground(this.m_backgroundColor);
- if (this.m_sShowButtons.compareTo("true") == 0 && (this.m_sOrder.compareTo("circular") == 0 || this.m_sOrder.compareTo("linear") == 0)) {
- ((Container)this).add(this.m_PrevButton);
- ((Container)this).add(this.m_NextButton);
- ((Container)this).add(this.m_playButton);
- }
-
- if (this.m_sShowButtons.compareTo("true") == 0) {
- this.m_nOffset = 15;
- } else {
- this.m_nOffset = 0;
- }
-
- }
-
- public boolean mouseDrag(Event evt, int x, int y) {
- return true;
- }
-
- public MORPHTEA() {
- this.m_backgroundColor = Color.blue;
- this.m_sOrder = "circular";
- this.m_sShowButtons = "true";
- this.PARAM_frps = "frps";
- this.PARAM_imageFile = "imageFile";
- this.PARAM_imageType = "imageType";
- this.PARAM_numImages = "numImages";
- this.PARAM_backgroundColor = "backgroundColor";
- this.PARAM_imageOrder = "imageOrder";
- this.PARAM_showButtons = "showButtons";
- }
- }
-