why it doest draw ???  
Author Message
polatay





PostPosted: 2004-4-19 23:18:00 Top

java-programmer, why it doest draw ??? in the below short write
i try to write an Thread examle that try to draw lines in every second
from (0,0) to (x, y).
x and y are random between 0..255
with first come to tWork (Thread) it draws, but next second and next
seconds it doesnt do any thing.
g and gr are the same and initalized
i cheked them with this command :
System.out.println(gr.equals(g)); //it prints "true"

question is why it doesnt draw line after second 1 ?

polat


------------------------------------------------------------

package mypackage1;

import java.applet.*;
import java.awt.*;
import javax.swing.JButton;


class tWork extends Thread
{
Graphics gr;

public tWork(Graphics g)
{
gr = g;
System.out.println(gr.equals(g)); //it prints "true"

}

public void run()
{
int x, y;

while (true)
{
x = (int)(Math.random()*255);
y = (int)(Math.random()*255);
gr.drawLine(0, 0, x, y);

try
{
this.sleep(1000);
}
catch (Exception e) {}
}
}
}


public class Basla extends Applet
{
Thread t;


public Basla()
{
this.setSize(300,300);
}

public void paint(Graphics g)
{
t = new tWork(g);
t.start();
}
}