//********************************************************************* //* Programmer : Jang Kyu-O(Àå ±Ô¿À) * //* Date : 1996/2/10 * //* E-Mail : kojang@ctkhost.ctk.co.kr * //* Tel : +82-02-3149-4821 * //* Address : Á¦À̾¾Çö ¿¤¸²³×Æ®»ç¾÷º»ºÎ À¥ÆÀ * //********************************************************************* import java.applet.*; import java.awt.*; import java.util.*; import java.net.MalformedURLException; public class DasenAnim extends Applet implements Runnable { int delay; boolean isbegin=true; Thread animator; boolean onanim=true; Image animDasenimg, picimg; Graphics animDasenmap; Rectangle r; int numimg; int count=0; Hashtable frames; MediaTracker tracker; AudioClip background; AudioClip bubble; boolean isloaded=false; int image_w=120, image_h=100; static String abridge(String s, int len) { String ellipsis = "..."; if (len >= s.length()) { return s; } int trim = len - ellipsis.length(); return s.substring(0, trim / 2)+ellipsis+ s.substring(s.length() - trim / 2); } void tellLoadingMsg(String file, String fileType) { showStatus("DASEN : loading "+fileType+" "+abridge(file, 20)); } void clearLoadingMessage() { showStatus(""); } void parseImages(String attr) throws MalformedURLException { frames = new Hashtable(); tracker = new MediaTracker(this); int leng=0; for (int i = 0 ; i < numimg ; i++) { int next = attr.indexOf('|', leng); if (next == -1) next = attr.length(); String s = attr.substring(leng, next); if (s.length() != 0) { tellLoadingMsg("images/"+s, "images"); Image animDasenimg = getImage(getCodeBase(), "images/"+s); frames.put(new Integer(i), animDasenimg); tracker.addImage(animDasenimg, 0); // System.out.println("images/"+s); } leng = next + 1; } clearLoadingMessage(); } /** * Initialize the applet and compute the delay between frames. */ public void init() { String str=null; try { str = getParameter("imgnumber"); } catch(Exception e) { System.out.println(e); } numimg = (str != null) ? Integer.parseInt(str) : 1; // System.out.println("Number of Images : "+numimg); try { str = getParameter("delay"); } catch(Exception e) { System.out.println(e); } delay = (str != null) ? Integer.parseInt(str) : 1000; // System.out.println("Delay : "+delay); try { str = getParameter("images"); // System.out.println("Images : "+str); parseImages(str); } catch(Exception e) { System.out.println(e); } tellLoadingMsg("audio/spacemusic.au", "audio"); background = getAudioClip(getCodeBase(), "audio/spacemusic.au"); tellLoadingMsg("audio/bubble1.au", "audio"); bubble = getAudioClip(getCodeBase(), "audio/bubble1.au"); } /** * This method is called when the applet becomes visible on * the screen. Create a thread and start it. */ public void start() { animator = new Thread(this); animator.start(); // Start the background music background.loop(); } /** * This method is called when the applet is no longer * visible. Set the animator variable to null so that the * thread will exit before displaying the next frame. */ public void stop() { animator = null; // Stop the background music background.stop(); } public boolean mouseDown(Event evt, int x, int y) { if(isloaded==false) return true; if(onanim==true) onanim=false; else onanim = true; return true; } /** * This method is called by the thread that was created in * the start method. It does the main animation. */ public void run() { while (Thread.currentThread() == animator) { repaint(); if(onanim==true) { count++; count %= numimg; } try { if(isloaded==true) Thread.sleep(100); else Thread.sleep(20); } catch (InterruptedException e) { break; } } } // ¹ÙÅÁÀ» Áö¿î´Ù. private void setBatang(Graphics g) { g.setColor(new Color(0, 0, 140)); g.fillRect(0, 0, r.width, r.height); } /** * Paint the previous frame (if any). */ public void paint(Graphics g) { r = bounds(); if(isbegin==true) { animDasenimg = createImage(image_w, image_h); animDasenmap = animDasenimg.getGraphics(); picimg = getImage(getCodeBase(), "images/"+"pic.gif"); isbegin = false; } update(g); } String waitMessage = "Àá½Ã ±â´Ù·Á ÁÖ¼¼¿ä. À̹ÌÁö¸¦ Àаí ÀÖ½À´Ï´Ù."; String waitMessageEng = "Please Wait! Reading images..."; int msgstart=0; Font font = new Font("Helvista", 1, 16); FontMetrics fontx = getFontMetrics(font); /** * Update a frame of animation. */ public void update(Graphics g) { if(tracker.statusID(0, true) == MediaTracker.COMPLETE) { animDasenmap.drawImage( (Image)frames.get(new Integer(count)), 0, 0, this); isloaded=true; } else { setBatang(animDasenmap); animDasenmap.setFont(font); animDasenmap.setColor(Color.yellow); animDasenmap.drawString(waitMessage, image_w-msgstart++, 40); animDasenmap.setColor(Color.white); animDasenmap.drawString(waitMessageEng, image_w-msgstart++, 60); int msgleng = fontx.stringWidth(waitMessage); if( msgleng+image_w < msgstart) msgstart=0; } // Paint the image onto the screen g.drawImage( animDasenimg, 0, 0, this); if ((count % 3) == 0) { bubble.play(); } } }