import browser.Applet;
import awt.Color;
import awt.Font;
import awt.Graphics;

class BeatingMessage extends Applet implements Runnable {
       Color  textColor=null;
       Font   textFont=null;
       String message=null;
       int    stateFlag=0;
       Thread beatingThread=null;

       public void init() {
             String size = getAttribute("size");
             String style = getAttribute("style");
             String family = getAttribute("family");
             int fontSize;

             if ( size != null ) {
                  if ( size.equals("large")
                       || size.equals("LARGE") || size.equals("Large") )
                     fontSize=36;
                  else if ( size.equals("small")
                       || size.equals("SMALL") || size.equals("Small") )
                     fontSize=10;
                  else
                     fontSize=14;
              }  
             else
                     fontSize=14;

             if ( family == null ) family = "TimesRoman";

             if ( style != null ) {
                  if ( style.equals("italic")
                       || style.equals("ITALIC") || style.equals("Italic") )
                     textFont = getFont(family, Font.ITALIC, fontSize);
                  else if ( style.equals("bold")
                       || style.equals("BOLD") || style.equals("Bold") )
                     textFont = getFont(family, Font.BOLD, fontSize);
                  else
                     textFont = getFont(family, Font.PLAIN, fontSize);
              }  
              else
                     textFont = getFont(family, Font.PLAIN, fontSize);

             message = getAttribute("value");
             if ( message == null )  message = "Welcome to Wakkanai!";

             resize( textFont.stringWidth(message) + 8, textFont.size + 18 );
       }

       public void paint( Graphics g ) {
             Color  textColor=null;

             g.setFont( textFont );

             if( stateFlag == 0 ) {
                  textColor = awt.Color.darkGray;
                  g.setForeground( textColor );
                  g.drawString( message, 3, textFont.size );

                  textColor = awt.Color.white;
                  g.setForeground( textColor );
                  g.drawString( message, 5, textFont.size + 2 );

                  textColor = awt.Color.lightGray;
                  g.setForeground( textColor );
                  g.drawString( message, 4, textFont.size + 1 );
             }
             else if( stateFlag == 1 ) {
                  g.clearRect( 0, 0, 
                     textFont.stringWidth(message) + 8, textFont.size + 18 );
             }
             else stateFlag=0;
       }

       public void stop() {
             if( beatingThread != null ) {
                   beatingThread = null;
             }
       }

       public void run() {
             while( beatingThread.isAlive() ) {
                  repaint();
                  if( stateFlag == 0 )
                     Thread.sleep(1600);
                  else
                     Thread.sleep(400);

                  stateFlag++; stateFlag%=2;
             }
       }

       public void mouseEnter() {
             if( beatingThread == null ) {
                   beatingThread = new Thread(this);
                   beatingThread.start();
             }
             else if( beatingThread.isAlive() ) {
                   beatingThread.stop();
             }
             else {
                   beatingThread.start();
             }
       }
}

