/* "Ultraman.java" */ /* 1996 J.H. Rosen */ /* java applet, pose-able "Ultraman Toro", with arms-up action */ import java.applet.Applet; import java.awt.*; public class Ultraman extends java.applet.Applet implements Runnable { /* variables */ /* font */ Font txt_Font; /* images */ /* Ultraman body gif */ Image body_Image; /* Ultraman left arm up gif */ Image arm_left_up_Image; /* Ultraman left arm down gif */ Image arm_left_down_Image; /* Ultraman right arm up gif */ Image arm_right_up_Image; /* Ultraman right arm down gif */ Image arm_right_down_Image; /* Ultraman, MediaTracker */ MediaTracker ultraman_MediaTracker; /* Ultraman, offscreen graphics context (composite buffer) */ Image offUltraman_Image; Graphics offUltraman_Graphics; /* Ultraman, arms down/up flag (0=down;1=up) */ int armsUpDown_Flg; /* Ultraman, animation thread */ Thread animation_Thread; /* methods invoked by Java */ /* "init()" * initialize the applet */ public void init() { /* 225W X 519H canvas */ resize(225,519); /* text font */ txt_Font = new Font("Helvetica", Font.PLAIN, 9); /* create offscreen graphics context, Ultraman composite buffer */ /* rect = 0,0,225,519 (225W X 519H) */ offUltraman_Image = createImage(225,519); offUltraman_Graphics = offUltraman_Image.getGraphics(); /* retrieve .gif images */ /* body (123W X 490H) */ body_Image = getImage(getCodeBase(),"images/body.gif"); /* arm, left/down (47W X 160H) */ arm_left_down_Image = getImage(getCodeBase(),"images/arm_left_down.gif"); /* arm, right/down (56W X 162H) */ arm_right_down_Image = getImage(getCodeBase(),"images/arm_right_down.gif"); /* arm, left/up (43W X 147H) */ arm_left_up_Image = getImage(getCodeBase(),"images/arm_left_up.gif"); /* arm, right/up (40W X 161H) */ arm_right_up_Image = getImage(getCodeBase(),"images/arm_right_up.gif"); /* init "Ultraman" MediaTracker */ ultraman_MediaTracker = new MediaTracker(this); /* load images into MediaTracker */ ultraman_MediaTracker.addImage(body_Image,0); ultraman_MediaTracker.addImage(arm_left_down_Image,1); ultraman_MediaTracker.addImage(arm_right_down_Image,2); ultraman_MediaTracker.addImage(arm_left_up_Image,3); ultraman_MediaTracker.addImage(arm_right_up_Image,4); /* init arms down/up flag (0=down;1=up) */ armsUpDown_Flg = 0; } /* end method "init" */ /* "start()" * called when the applet becomes visible on screen */ public void start() { /* start scrolling logo animator thread */ animation_Thread = new Thread(this); animation_Thread.start(); } /* end method "start" */ /* "run()" * called (repeatedly) by the Thread created in "start()" */ public void run() { /* update scrolling logo animator thread */ while (Thread.currentThread() == animation_Thread) { /* repaint (update) the screen */ repaint(); /* begin: thread delay (125 milliseconds) */ try { Thread.sleep(125); } catch (InterruptedException e) { break; } /* end: thread delay */ } /* end "while (Thread.currentThread() == animation_Thread)" */ } /* end method "run" */ /* "stop()" * called when the applet is no longer visible on screen */ public void stop() { /* stop scrolling logo animator thread */ if (animation_Thread != null) animation_Thread.stop(); animation_Thread = null; } /* end method "stop" */ /* "destroy()" * called just before the browser exits */ public void destroy() { /* dispose offscreen Graphics Object, Ultraman composite buffer */ offUltraman_Graphics.dispose(); offUltraman_Graphics = null; } /* end method "destroy" */ /* "mouseDown()" * called when the mouse button is pressed down */ public boolean mouseDown(Event evt, int x, int y) { /* Ultraman, arms down/up flag (0=down;1=up) */ armsUpDown_Flg = 1; // flag arms up (1) /* force repaint */ repaint(); return true; } /* end method "mouseDown" */ /* "mouseUp()" * called when the mouse button comes back up */ public boolean mouseUp(Event evt, int x, int y) { /* Ultraman, arms down/up flag (0=down;1=up) */ armsUpDown_Flg = 0; // flag arms down (0) /* force repaint */ repaint(); return true; } /* end method "mouseUp" */ /* "update()" * update the screen */ public void update(Graphics g) { /* (intercepting "update" avoids background erase) */ /* call "paint" */ paint(g); } /* end method "update" */ /* "paint()" * paint the screen */ public void paint(Graphics g) { /* fill buffer with white paint */ offUltraman_Graphics.setColor(Color.white); offUltraman_Graphics.fillRect(0,0,225,519); /* frame entire buffer with black color */ offUltraman_Graphics.setColor(Color.black); offUltraman_Graphics.drawRect(0,0,224,518); /* wait for images to laod before drawing */ if (ultraman_MediaTracker.checkAll(true) == true) { /* draw body (in buffer) */ offUltraman_Graphics.drawImage(body_Image,5+42,5+19,this); /* draw arms down (in buffer) */ /* Ultraman, arms down/up flag (0=down;1=up) */ if (armsUpDown_Flg == 0) { offUltraman_Graphics.drawImage(arm_left_down_Image,5+0,5+135,this); offUltraman_Graphics.drawImage(arm_right_down_Image,5+159,5+125,this); } else { offUltraman_Graphics.drawImage(arm_left_up_Image,5+4,5+12,this); offUltraman_Graphics.drawImage(arm_right_up_Image,5+159,5+0,this); } } // end "if (ultraman_MediaTracker.checkAll(true) == true)" /* begin: write text message, "Loading Images..." */ else { /* set text string font */ offUltraman_Graphics.setFont(txt_Font); /* set text string color */ offUltraman_Graphics.setColor(Color.black); /* write/draw text message */ offUltraman_Graphics.drawString("Loading Images...",25,25); } /* end: write text message, "Loading Images..." */ /* blast buffer to screen */ g.drawImage(offUltraman_Image,0,0,this); } /* end method "paint" */ } /* end class "Ultraman" */ /* end file "Ultraman.java" */