// Marquee.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Marquee extends JApplet implements ActionListener { private int animationDelay; // millisecond delay. from PARAM private Timer animationTimer; // Timer drives animation private String msg; //from PARAM in HTML file private int count; // respond to Timer's event public void actionPerformed( ActionEvent actionEvent ) { repaint(); // repaint animator } // start or restart animation public void startAnimation() { if ( animationTimer == null ) { animationTimer = new Timer( animationDelay, this ); animationTimer.start(); } else // continue from last image displayed if ( ! animationTimer.isRunning() ) animationTimer.restart(); } // stop animation timer public void stopAnimation() { animationTimer.stop(); } public void init() { msg = getParameter( "message" ); //from PARAM in HTML file animationDelay = Integer.parseInt( getParameter( "delay" ) ); startAnimation(); // begin animation } public void paint (Graphics g) { super.paint(g); char ch = msg.charAt(0); msg = msg.substring(1,msg.length()); msg += ch; g.setFont( new Font( "Helvetica", Font.BOLD, 20 ) ); g.drawString( msg, 30, 30 ); count++; if (count == 10) resize( getWidth()*2, getHeight()/2 ); //only in appletviewer? } }