JTF > Demo Gallery > acm.graphics > TimesSquare

This program animates a text string so that it moves across the screen from left to right in the manner of the headline displays in New York’s Times Square. The code for the run method looks like this:

 

public void run() {
   GLabel label = new GLabel(HEADLINE);
   label.setFont("Serif-72");
   add(label, getWidth(), (getHeight() + label.getAscent()) / 2);
   while (label.getX() + label.getWidth() > 0) {
      label.move(-DELTA_X, 0);
      pause(PAUSE_TIME);
   }
}
 
private static final int DELTA_X = 2;
private static final int PAUSE_TIME = 20;
private static final String HEADLINE =
  "When in the course of human events . . .";