Please help! Scroll timing question
Here's my code (sorry so long!):
***********
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
public class ScrollWindow extends Applet implements Runnable {
Image winScratch;
Graphics gScratch;
Thread runner;
String[] lines = new String[1000];
int nlines, mlines, topline, fmh;
Color textcolor = new Color(255, 255, 255);
Color textbackground = new Color(0, 0, 51);
boolean isRunning = false;
int delay = 3;
public void init() {
int i;
String s;
Font f = new Font("Arial", Font.PLAIN, 10);
FontMetrics fm = getFontMetrics(f);
fmh = fm.getHeight();
mlines = (getSize().height - 10) / fmh;
winScratch = createImage(this.getSize().width, this.getSize().height);
gScratch = winScratch.getGraphics();
setBackground(Color.white);
s = getParameter("delay");
if (s != null)
delay = Integer.parseInt(s);
s = getParameter("textcolor");
if (s != null)
textcolor = new Color(Integer.parseInt(s, 16));
s = getParameter("textbackground");
if (s != null)
textbackground = new Color(Integer.parseInt(s, 16));
for (i = 0; i < 1000; i++) {
lines = getParameter("line" + (i + 1));
if (lines == null)
break;
}
nlines = i;
topline = 0;
}
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
runner = null;
}
public void run() {
Thread thisThread = Thread.currentThread();
while (runner == thisThread) {
repaint();
if (isRunning && nlines > mlines) {
topline++;
if (topline == nlines)
topline = 0;
}
isRunning = true;
try {
Thread.sleep(delay * 1000);
} catch(InterruptedException e) { }
}
}
public void paint(Graphics g) {
int w, h, i, cnt;
String[] dlines = new String[mlines];
w = getSize().width;
h = getSize().height;
Font f = new Font("Arial", Font.PLAIN, 10);
cnt = 0;
for (i = 0; i < mlines; i++) {
if (topline + i < nlines) {
dlines = lines[topline + i];
}
else {
if (nlines > mlines) {
dlines = lines[cnt];
cnt++;
}
else {
dlines = "";
}
}
}
gScratch.drawRect(0, 0, w - 0, h - 0);
gScratch.setColor(textbackground);
gScratch.fillRect(0, 0, w - 0, h - 0);
gScratch.setFont(f);
gScratch.setColor(textcolor);
for (i = 0; i < mlines; i++) {
gScratch.drawString(dlines, 5, fmh * (i + 1) + 5);
}
g.drawImage(winScratch, 0, 0, this);
}
public final void update(Graphics g) {
paint(g);
}
}
*****************
The applet scrolls so choppy that you can't even tell it's scrolling (applet is only 21 pixels high) and I'm not sure what to change in order to smooth it out.
Any suggestions?
Thank you!

