import java.applet.Applet; import java.awt.*; public class ticker3 extends Applet implements Runnable { String myText; Thread myThread; Font myFont; FontMetrics myMetrics; Color myColor; int myTextLength; int XCoord = 0; int myAdvance = 2; int mySleepPeriod = 50; public void init() { myText=getParameter("text"); myThread = null; myFont = new Font("Helvetica",1,24); myMetrics = getFontMetrics(myFont); myTextLength = myMetrics.stringWidth(myText); myColor = Color.blue; mySleepPeriod = 100; } public void newCoordinates() { if (XCoord < -myTextLength) { XCoord = size().width; } else { XCoord = XCoord - myAdvance; } } public void start() { if (myThread == null) { myThread = new Thread(this,"MyThread"); myThread.start(); } } public void run() { while (myThread != null) { newCoordinates(); repaint(); try { myThread.sleep(mySleepPeriod); } catch (InterruptedException e) {} } } public void paint(Graphics g) { g.setColor(Color.black); g.fillRect(0,0,size().width,size().height); g.setColor(myColor); g.setFont(myFont); g.drawString(myText,XCoord,25); } public void stop() { myThread.stop(); myThread = null; } }