the following applet is supposed to draw random lines on the screen, but
doesn't. does anyone know how to make it refresh?
thanks in advance
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.text.*;
import java.lang.*;
public class UI2 extends Applet{
private int x1,y1,x2,y2;
public void init() {
for(;;) {
x1=(int)(Math.random()*100);
y1=(int)(Math.random()*100);
x2=(int)(Math.random()*100);
y2=(int)(Math.random()*100);
repaint();
}
}
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawLine(x1, y1, x2, y2);
}
public void update(Graphics g) {
paint(g);
}
}
Skip - 28 May 2005 16:54 GMT
> public void init() {
> for(;;) {
[quoted text clipped - 5 lines]
> }
> }
repaint() does not repaint straight away, but schedules it in another thread
which might be processed at any time in the future.
With your tight loop you don't give the other thread any time to process the
repaint-requests. Futher: this code never leaves the init() so it will
probably never reach paint(g)