import java.awt.*; public class ScrollingBanner extends AnimationApplet{ protected String text; protected Font font = new java.awt.Font("Sans-serif", Font.BOLD, 24); protected int x, y; protected int offset = 1; protected Dimension d; public void init() { // get parameters "delay" and "text" String att = getParameter("delay"); // set the delay of the animation if (att != null){ setDelay(Integer.parseInt(att)); } else{ setDelay(100); // default value } // set the text to show att = getParameter("text"); if (att != null) { text = att; } else { text = "Scrolling banner."; } // set initial position of the text d = getSize(); x = d.width; y = font.getSize(); } public void paint(Graphics g) { // get the font metrics to determine the length of the text g.setFont(font); FontMetrics fm = g.getFontMetrics(); int length = fm.stringWidth(text); // adjust the position of text from the previous frame x -= offset; // if the text is completely off to the left end // move the position back to the right end if (x < -length) x = d.width; // set the pen color and draw the background g.setColor(Color.black); g.fillRect(0,0,d.width,d.height); // set the pen color, then draw the text g.setColor(Color.green); g.drawString(text, x, y); } }