import java.applet.Applet; import java.awt.*; public class ticker4 extends Applet implements Runnable { String myText; Thread myThread; Font myFont; FontMetrics myMetrics; Image myImage; Graphics myOffsceenGraphics; Color myColor; int myTextLength; int XCoord = 0; int mySleepPeriod = 50; int myAdvance = 2; public void init() { myText=getParameter("text"); myThread = null; myFont = new Font("Helvetica",1,24); myMetrics = getFontMetrics(myFont); myTextLength = myMetrics.stringWidth(myText); myColor = Color.blue; myImage = createImage(size().width,size().height); myOffsceenGraphics = myImage.getGraphics(); } 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) { try { myThread.sleep(mySleepPeriod); } catch (InterruptedException e) {} newCoordinates(); repaint(); } } public void updateImage(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 update(Graphics g) { paint(g); } public void paint(Graphics g) { updateImage(myOffsceenGraphics); g.drawImage(myImage,0,0,null); } public void stop() { myThread.stop(); myThread = null; } }