/* 
   author: Neng-Fa Zhou
   This marquee applet greets you in different languages
*/
import java.awt.*;
import java.applet.Applet;

public class Greeting1 extends Applet {
  String[] messages = {
      "AnYoungHaSeYen",
      "BonJour",
      "BuenosDias",
      "Cao",
      "Czesc",
      "Ciao",
      "GutenTag",
      "KemoNacho",
      "KonNiChiWa",
      "Kumusta",
      "Hello",
      "Nihao",
      "Shalom",
      "Privet"};
  Color[] colors = {
    Color.black,      
    Color.blue,
    Color.cyan,
    Color.darkGray,
    Color.gray,
    Color.green,
    Color.magenta,
    Color.yellow,
    Color.green,
    Color.orange,
    Color.red,
    Color.pink,
    Color.red,
    Color.yellow
    };

  int startingMesNo = 0; /* index of the starting message */
  int startingCharNo = 0;  /* index of the starting char in the message */

  public void paint(Graphics g){
    while (true){
      startingCharNo++;     /* the next char will be the starting char */
      if (startingCharNo == messages[startingMesNo].length()){
	startingMesNo++;  /* the next word will be the starting word */
	if (startingMesNo==messages.length) startingMesNo=0;
	startingCharNo =0; 
      }
      try {
	Thread.sleep(500);
      }
      catch (InterruptedException e){
      }

      int x = 0; 
      int y = 30;
      g.setFont(new Font("Dialog",0,20));
      FontMetrics fm = g.getFontMetrics();
      String mes;

      // clean the applet
      g.setColor(getBackground());
      g.fillRect(0,0,getWidth(),getHeight());

    // draw the starting string
      mes = messages[startingMesNo].substring(startingCharNo,messages[startingMesNo].length());
      g.setColor(colors[startingMesNo]);
      g.drawString(mes,x,y);
      x += fm.stringWidth(mes)+10;

      // draw strings in messages[startingMesNo+1..]
      for (int i=startingMesNo+1;i<messages.length;i++){
	g.setColor(colors[i]);
	g.drawString(messages[i],x,y);
	x += fm.stringWidth(messages[i])+10;
      }

      // draw strings in messages[0..startingMesNo-1]
      for (int i=0;i<startingMesNo;i++){
	g.setColor(colors[i]);
	g.drawString(messages[i],x,y);
	x += fm.stringWidth(messages[i])+10;
      }

    // draw the remaining chars in messages[startingMesNo]
      mes = messages[startingMesNo].substring(0,startingCharNo);
      g.setColor(colors[startingMesNo]);
      g.drawString(mes,x,y);
    }
  }
}
