01: import java.applet.*; 02: import java.awt.*; 03: import java.awt.event.*; 04: import java.awt.font.*; 05: import java.awt.geom.*; 06: import javax.swing.*; 07: 08: public class BannerApplet extends Applet 09: { 10: public void init() 11: { 12: message = getParameter("message"); 13: String fontname = getParameter("fontname"); 14: int fontsize = Integer.parseInt(getParameter("fontsize")); 15: delay = Integer.parseInt(getParameter("delay")); 16: font = new Font(fontname, Font.PLAIN, fontsize); 17: Graphics2D g2 = (Graphics2D) getGraphics(); 18: FontRenderContext context = g2.getFontRenderContext(); 19: bounds = font.getStringBounds(message, context); 20: 21: timer = new Timer(delay, new 22: ActionListener() 23: { 24: public void actionPerformed(ActionEvent event) 25: { 26: start--; 27: if (start + bounds.getWidth() < 0) 28: start = getWidth(); 29: repaint(); 30: } 31: }); 32: } 33: 34: public void start() 35: { 36: timer.start(); 37: } 38: 39: public void stop() 40: { 41: timer.stop(); 42: } 43: 44: public void paint(Graphics g) 45: { 46: g.setFont(font); 47: g.drawString(message, start, (int)-bounds.getY()); 48: } 49: 50: private Timer timer; 51: private int start; 52: private int delay; 53: private String message; 54: private Font font; 55: private Rectangle2D bounds; 56: }