import java.awt.Graphics; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; public class Scroll extends java.applet.Applet implements Runnable { String msg=" yet another ticker tape.. v2.0.. "+ " send postcards to CvL@java.pages.de "; Font myFont; FontMetrics myFontM; int delay = 200; protected Thread daemon; protected boolean threadSuspended = false; protected int pixelsToGo = 0; public void init() { setBackground(Color.black); // if (size().width < 10 || size().height < 10) { // size().width = 500; // size().height = 50; // resize(size().width, size().height); // } String tmp = getParameter("message"); if (tmp != null) msg = tmp; // tmp = getParameter("delay"); // if (tmp != null) delay = Integer.parseInt(tmp); // if (delay == 0) delay++; delay = 225; int size = (int)((double)size().height * 0.66); // wild guess int style = Font.PLAIN; // tmp = getParameter("font.size"); // if (tmp != null) size = Integer.parseInt(tmp); size=36; // tmp = getParameter("font.style"); // if (tmp != null) style = Integer.parseInt(tmp); // tmp = getParameter("font.family"); // if (tmp == null) tmp = "Helvetica"; tmp = "Courier"; myFont = new Font(tmp, style, size); myFontM = getFontMetrics(myFont); } public void paint(Graphics g) { } public void update(Graphics g) { String buchstabe = msg.substring(0,1); msg = msg.substring(1) + buchstabe; pixelsToGo = myFontM.stringWidth(buchstabe) + (buchstabe.charAt(0) == ' ' ? 2 : +4); g.copyArea(pixelsToGo, 0, size().width-pixelsToGo, size().height, -pixelsToGo, 0); g.setColor(Color.black); g.fillRect(size().width-pixelsToGo, 0, size().width-1, size().height-1); g.setFont(myFont); // g.setColor(Color.red); g.setColor(Color.yellow); g.setColor(Color.red); g.drawString(buchstabe, size().width-(pixelsToGo+2), myFontM.getHeight()+1); g.drawString(buchstabe, size().width-(pixelsToGo+6), myFontM.getHeight()-1); g.setColor(Color.orange); g.drawString(buchstabe, size().width-(pixelsToGo+4), myFontM.getHeight()); } public void start() { if (daemon == null) { daemon = new Thread(this); daemon.start(); } } public void stop() { daemon.stop(); daemon = null; } public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while(daemon != null) { try {Thread.sleep(delay);} catch (InterruptedException e){} repaint(); } } public boolean mouseDown(java.awt.Event evt, int x, int y) { if (threadSuspended) daemon.resume(); else daemon.suspend(); threadSuspended = !threadSuspended; return true; } }