/********************************************************************************** * * * Shining Letters Applet * * ( ShinLetter.java ) * * Author : Seiichi Inoue * **********************************************************************************/ /********************** << Imported package class definition >> *******************/ import java.applet.Applet; /* Applet packages */ import java.awt.*; /* All of the Abstract Windowing Toolkit packages */ import java.lang.*; /* Lang packages */ /************************** <<Oneself of class definition>> ***********************/ // Class name : ShinLetter // Access control : public( Access possibility even from which class ) // Extends class : Applet // Implements class: Runnable( Use of Thread is enabled ) public class ShinLetter extends Applet implements Runnable { /************************* << Class attribute of definition >> ********************/ Thread kicker = null; /* Thread(Initial value:suspension) */ Dimension d; /* Display range */ Image offs; /* Off screen */ Graphics grf; /* Drawing range */ String msg; /* Display letter housing */ int no; /* Number of letter */ int width; /* Shining letter display position */ String cen; /* Shining letter( One character ) */ String bef; /* Letter to shining letter */ int speed; /* Display speed */ String param; /* Parameter reading */ int backred,backgreen,backblue; /* Background color parameter */ Color backcolor; /* Background color */ int mojired,mojigreen,mojiblue; /* Letter color parameter */ Color mojicolor; /* Letter color */ int shinred,shingreen,shinblue; /* Shining letter color parameter */ Color shincolor; /* Shining letter color */ Font font; /* Letter font */ String fontname; /* Letter font parameter */ int fontsize; /* Letter size parameter */ int strHeight; /* Letter height */ int y_Point; /* Display position ( Height ) */ /***************** << Class of method (implementation procedure) >> ***************/ // /******** Initialization (init) method *********/ public void init() { d = size(); /* Set display screen size */ offs = createImage(d.width,d.height); /* Off scr area preparation */ grf = offs.getGraphics(); /* Graphics object extraction */ param = getParameter("message"); /* Letter parameter reading */ msg = (param != null)? /* Input determination */ param: "TEXT ERORR"; /* No desig -> TEXT ERORR */ msg = " " + msg + " "; /* Blank addition(For disp effect)*/ no = msg.length(); /* Number of the letter */ param = getParameter("speed"); /* Display speed parameter reading*/ speed = (param != null)? /* Input determination */ Integer.parseInt(param): 50; param = getParameter("font"); /* Font kind parameter reading */ fontname = (param != null)? /* Input determination */ param: "Dialog"; param = getParameter("fontsize"); /* Font size parameter reading */ fontsize = (param != null)? /* Input determination */ Integer.parseInt(param): 35; param = getParameter("fonttype"); /* Font type parameter reading */ if ( "BOLD".equals (param) ) /* BOLD ? */ font = new Font(fontname,Font.BOLD,fontsize); /* Set BOLD */ else { if ( "ITALIC".equals (param) ) /* ITALIC ? */ font = new Font(fontname,Font.ITALIC,fontsize); /* Set ITALIC */ else font = new Font(fontname,Font.PLAIN,fontsize); /* Set PLAIN */ } strHeight = (getFontMetrics(font)).getLeading(); /* Vertical position cal*/ strHeight -= (getFontMetrics(font)).getDescent(); strHeight += (getFontMetrics(font)).getAscent(); y_Point = (d.height + strHeight /* Set vertical position*/ - (getFontMetrics(font)).getDescent())/2; param = getParameter("backred"); /* Background red reading */ backred = (param != null)? /* Input determination */ Integer.parseInt(param): 255; param = getParameter("backgreen"); /* Background green reading */ backgreen = (param != null)? /* Input determination */ Integer.parseInt(param): 255; param = getParameter("backblue"); /* Background blue reading */ backblue = (param != null)? /* Input determination */ Integer.parseInt(param): 255; backcolor = new Color /* Background color assembly */ (backred,backgreen,backblue); param = getParameter("mojired"); /* Letter red reading */ mojired = (param != null)? /* Input determination */ Integer.parseInt(param): 0; param = getParameter("mojigreen"); /* Letter green reading */ mojigreen = (param != null)? /* Input determination */ Integer.parseInt(param): 0; param = getParameter("mojiblue"); /* Letter blue reading */ mojiblue = (param != null)? /* Input determination */ Integer.parseInt(param): 255; mojicolor = new Color /* Letter color assembly */ (mojired,mojigreen,mojiblue); param = getParameter("shinred"); /* Shining letter red reading */ shinred = (param != null)? /* Input determination */ Integer.parseInt(param): 255; param = getParameter("shingreen"); /* Shining letter green reading */ shingreen = (param != null)? /* Input determination */ Integer.parseInt(param): 255; param = getParameter("shinblue"); /* Shining letter blue reading */ shinblue = (param != null)? /* Input determination */ Integer.parseInt(param): 0; shincolor = new Color /* Shining letter color assembly */ (shinred,shingreen,shinblue); } /* End of initial method */ /************ Start (start) method *************/ public void start() { if ( kicker == null ) { /* Kicker is null? ( Suspension? )*/ kicker = new Thread(this); /* YES: kicker setting */ kicker.start(); /* Setting of start */ } } /* End of start method */ /*********** Repeatedly (run) method ***********/ public void run() { int i; /* Counter variable declaration */ while (true) { /* Repeatedly */ try { /* Interruption confirmation */ for(i=0; i<no-1; i++) { /* Repeats to the number of letter*/ bef = msg.substring(0, i); /* Pickup letter from top */ cen = msg.substring(i, i+1);/* Pickup letter counter shows */ kicker.sleep(speed); /* Waiting ( mSEC ) */ repaint(); /* Drawing triggering */ } kicker.sleep(speed); /* Waiting of next cycle ( mSEC ) */ } catch(InterruptedException e) {} /* Interruption processing */ } } /* End of run method */ /*********** Renewal (update) method ***********/ public void update(Graphics g) { /* Lost of screen flickering */ paint(g); /* Drawing */ } /* End of update method */ /*********** Drawing (paint) method ************/ public void paint(Graphics g) { grf.setColor(backcolor); /* Set display back color */ grf.fillRect(0,0,d.width,d.height); /* Display range is applied */ FontMetrics fm = getFontMetrics(font); /* Get font information */ grf.setFont(font); /* Set font */ width = fm.stringWidth(bef); /* Get position of shining letter */ grf.setColor(mojicolor); /* Set letter color */ grf.drawString(msg,0,y_Point); /* Set letter */ grf.setColor(shincolor); /* Set shining letter color */ grf.drawString(cen,width,y_Point); /* Set shining letter */ g.drawImage(offs,0,0,this); /* Drawing setting */ } /* End of paint method */ /************ Stop (stop) method ***************/ public void stop() { if( kicker != null ) { /* Kicker is not null?( action? ) */ kicker.stop(); /* Set kicker to suspension */ kicker = null; /* Set kicker suspension condition*/ } } /* End of stop method */ } /* End of class setting */ /********************************************************************************** * End of Shining Letters Applet * **********************************************************************************/