/* "RevAl_MagicMedallion.java" */ /* 1997 Joe Rosen */ /* java applet, "Rev. Al Sharpton" (Magic Medallion) */ import java.applet.Applet; import java.awt.*; public class RevAl_MagicMedallion extends java.applet.Applet implements Runnable { /* program constants */ /* main portrait width and height */ final int MAIN_WDTH = 381; final int MAIN_HGHT = 361; /* animated miniature medallion top/left */ final int ANIM_MEDAL_TOP = 281; final int ANIM_MEDAL_LEFT = 173; /* animated miniature medallion width and height */ final int ANIM_MEDAL_WDTH = 50; final int ANIM_MEDAL_HGHT = 51; /* magnified (large) medallion top/left */ final int LRG_MEDAL_TOP = 7; final int LRG_MEDAL_LEFT = 249; /* magnified (large) medallion width and height */ final int LRG_MEDAL_WDTH = 125; final int LRG_MEDAL_HGHT = 127; /* variables */ /* images */ /* main portrait gif */ Image main_Image; /* animated miniature medallion gifs (5 images) */ Image anim_MiniMedallion[]; /* full-size (large) medallion gifs (5 images) */ Image large_Medallion[]; /* medallion gifs index (alternate between 5 images) */ int medallion_Idx; /* miniature medallion animation flag */ boolean miniMedallionAnm_Flg; /* medallion word balloon idx */ int madallionBalloon_Flg; // 2 phrases (1/2) /* Rev. Al, MediaTracker */ MediaTracker revAl_MediaTracker; /* Rev. Al, offscreen graphics context (composite buffer) */ Image offRevAl_Image; Graphics offRevAl_Graphics; /* magnifying ray polygon */ Polygon magRayPoly; /* magnifying ray polygon flag */ boolean magRayPoly_Flg; /* Rev. Al, animation thread */ Thread animation_Thread = null; /* methods invoked by Java */ /* "init()" * initialize the applet */ public void init() { // initialization loop counter int lpCnt; /* resize canvas */ resize(MAIN_WDTH + 1,MAIN_HGHT + 1); /* create offscreen graphics context, Rev. Al composite buffer */ offRevAl_Image = createImage(MAIN_WDTH,MAIN_HGHT); offRevAl_Graphics = offRevAl_Image.getGraphics(); /* retrieve .gif images */ /* main portrait (381W X 393H) */ main_Image = getImage(getCodeBase(),"images/medal_portrait.gif"); /* animated miniature medallions (50W X 51H) */ anim_MiniMedallion = new Image[5]; anim_MiniMedallion[0] = getImage(getCodeBase(),"images/sml_medal_1.gif"); anim_MiniMedallion[1] = getImage(getCodeBase(),"images/sml_medal_2.gif"); anim_MiniMedallion[2] = getImage(getCodeBase(),"images/sml_medal_3.gif"); anim_MiniMedallion[3] = getImage(getCodeBase(),"images/sml_medal_4.gif"); anim_MiniMedallion[4] = getImage(getCodeBase(),"images/sml_medal_5.gif"); /* full-size (large) medallion gifs (5 images) */ large_Medallion = new Image[5]; large_Medallion[0] = getImage(getCodeBase(),"images/lrg_medal_1.gif"); large_Medallion[1] = getImage(getCodeBase(),"images/lrg_medal_2.gif"); large_Medallion[2] = getImage(getCodeBase(),"images/lrg_medal_3.gif"); large_Medallion[3] = getImage(getCodeBase(),"images/lrg_medal_4.gif"); large_Medallion[4] = getImage(getCodeBase(),"images/lrg_medal_5.gif"); /* init Rev. Al MediaTracker */ revAl_MediaTracker = new MediaTracker(this); /* load images into MediaTracker */ revAl_MediaTracker.addImage(main_Image,0); for (lpCnt = 0; lpCnt < 5; lpCnt++) revAl_MediaTracker.addImage(anim_MiniMedallion[lpCnt],lpCnt + 1); for (lpCnt = 0; lpCnt < 5; lpCnt++) revAl_MediaTracker.addImage(large_Medallion[lpCnt],lpCnt + 6); /* init medallion gifs index (alternate between 5 images) */ medallion_Idx = 0; // init to 1st image /* init miniature medallion animation flag */ miniMedallionAnm_Flg = true; // initially animating /* init/create magnifying ray polygon */ magRayPoly = new Polygon(); magRayPoly.addPoint(372,70); magRayPoly.addPoint(198,306); magRayPoly.addPoint(250,70); /* init magnifying ray polygon flag */ magRayPoly_Flg = false; // initially not visible } /* end method "init" */ /* "start()" * called when the applet becomes visible on screen */ public void start() { /* start 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 animator thread */ while (Thread.currentThread() == animation_Thread) { /* inc/reset medallion gifs index (alternate between 5 images) */ if (miniMedallionAnm_Flg == true) { if (medallion_Idx < 4) medallion_Idx++; else medallion_Idx = 0; } /* repaint (update) the screen */ repaint(); /* begin: thread delay (250 milliseconds) */ try { Thread.sleep(250); } 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 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 context, Rev. Al composite buffer */ offRevAl_Graphics.dispose(); offRevAl_Graphics = null; } /* end method "destroy" */ /* "mouseDown()" * called when the mouse button is pressed down */ public boolean mouseDown(Event evt, int x, int y) { /* suspend miniature medallion anim */ miniMedallionAnm_Flg = false; /* mark magnifying ray polygon flag */ magRayPoly_Flg = true; // mark visible /* init medallion word balloon idx */ madallionBalloon_Flg = 1; // 1st (of 2) phrases /* force immediate 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) { /* resume miniature medallion anim */ miniMedallionAnm_Flg = true; /* mark magnifying ray polygon flag */ magRayPoly_Flg = false; // mark invisible /* force immediate 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) { /* font */ Font txt_Font; /* wait for images to laod before drawing */ if (revAl_MediaTracker.checkAll(true) == true) { /* draw main portrait (in buffer) */ offRevAl_Graphics.drawImage(main_Image,0,0,this); /* draw animated miniature medallion gif */ offRevAl_Graphics.drawImage( anim_MiniMedallion[medallion_Idx],ANIM_MEDAL_LEFT,ANIM_MEDAL_TOP,this ); /* draw magnifying rays and large medallion (?) */ if (magRayPoly_Flg == true) { // offRevAl_Graphics.drawPolygon(magRayPoly); offRevAl_Graphics.setColor(Color.black); offRevAl_Graphics.drawLine(198,306,250,70); offRevAl_Graphics.drawLine(198,306,372,70); offRevAl_Graphics.setColor(Color.cyan); offRevAl_Graphics.drawLine(198,306,251,70); offRevAl_Graphics.drawLine(198,306,252,70); offRevAl_Graphics.drawLine(198,306,371,70); offRevAl_Graphics.drawLine(198,307,370,70); offRevAl_Graphics.drawImage( large_Medallion[medallion_Idx],LRG_MEDAL_LEFT,LRG_MEDAL_TOP,this ); offRevAl_Graphics.setColor(Color.black); /* text font */ txt_Font = new Font("Helvetica", Font.BOLD, 12); /* write/draw text message */ switch (medallion_Idx) { /* chasid */ case 0: if (madallionBalloon_Flg == 1) { offRevAl_Graphics.drawString("I AM A",LRG_MEDAL_LEFT+45,LRG_MEDAL_TOP+25); madallionBalloon_Flg = 2; } else { offRevAl_Graphics.drawString("CHASID.",LRG_MEDAL_LEFT+45,LRG_MEDAL_TOP+25); madallionBalloon_Flg = 1; } break; /* Ed Koch */ case 2: if (madallionBalloon_Flg == 1) { offRevAl_Graphics.drawString("I WAS",LRG_MEDAL_LEFT+45,LRG_MEDAL_TOP+25); madallionBalloon_Flg = 2; } else { offRevAl_Graphics.drawString("THE MAYOR.",LRG_MEDAL_LEFT+35,LRG_MEDAL_TOP+25); madallionBalloon_Flg = 1; } break; } // end "switch (medallion_Idx)" } } // end "if (revAl_MediaTracker.checkAll(true) == true)" /* begin: write text message, "Loading Images..." */ else { /* text font */ txt_Font = new Font("Helvetica", Font.PLAIN, 9); /* fill buffer with white paint */ offRevAl_Graphics.setColor(Color.white); offRevAl_Graphics.fillRect(0,0,MAIN_WDTH,MAIN_HGHT); /* set text string font */ offRevAl_Graphics.setFont(txt_Font); /* set text string color */ offRevAl_Graphics.setColor(Color.black); /* write/draw text message */ offRevAl_Graphics.drawString("Loading Images...",25,25); } /* end: write text message, "Loading Images..." */ /* frame entire buffer with black color */ offRevAl_Graphics.setColor(Color.black); offRevAl_Graphics.drawRect(0,0,MAIN_WDTH - 1,MAIN_HGHT - 1); /* blast buffer to screen */ g.drawImage(offRevAl_Image,0,0,this); } /* end method "paint" */ } /* end class "RevAl_MagicMedallion" */ /* end file "RevAl_MagicMedallion.java" */