import java.awt.*;
public class MarqueeCanvas extends Canvas {
 String message;
 int position, drop, initialPosition, delta, messageWidth;
 Font messageFont = new Font("TimesRoman", Font.BOLD, 24);
 boolean ready = false;
 public MarqueeCanvas (String s) {
  message = s;
 }
 public void decrementPosition() {
  if (position + messageWidth < 0) {
   position = initialPosition;
  }
  else {
   position = position - delta;
  }
  repaint();
 }
 public void paint(Graphics g) {
  if (ready) {
   g.setFont(messageFont);
   g.drawString(message, position, drop);
  }
  else {
   Dimension d = size(); 
   position = initialPosition = d.width;
   g.setFont(messageFont);
   FontMetrics f = g.getFontMetrics();
   messageWidth = f.stringWidth(message);
   delta = f.stringWidth("e");
   drop = (d.height + f.getHeight() + f.getDescent()) / 2;
   ready = true;
  }
 }
 public Dimension minimumSize() {return new Dimension(300, 50);}
 public Dimension preferredSize() {return new Dimension(300, 50);}
}
