SRL Archive - Java Help and Tutorials

Muilti-thread to draw the mouse


rj

2013-07-04 22:32:08

So I tried to create a method to muilti-thread and draw the mouse for a script:

@Override
public void drawMouse(Graphics g) {
final Point mouse = Mouse.getInstance().getPoint();
g.setColor(Color.green);
g.drawLine(mouse.x - 1000, mouse.y, mouse.x + 1000, mouse.y);
g.drawLine(mouse.x, mouse.y - 1000, mouse.x, mouse.y + 1000);
}

But I get this error:


I can put the code in my pain method, but it will only draw the mouse once and then not update it, but it will update it if I move the mouse myself :s

Sin

2013-07-04 23:15:20

thread t() {

drawMouse(g)
}
t.start();


?

rj

2013-07-04 23:19:40

From: Sin
thread t() {

drawMouse(g)
}
t.start();


?

Like this?


drawMouse cannot be resolved to a variable

Kevin

2013-07-04 23:29:13

From: Officer Barbrady
Like this?


drawMouse cannot be resolved to a variable

Sin gave you the exact code. You changed it.

He declared a thread that would draw the mouse and then started the thread. You tried combining them into one OOP call which you can't really do without a lot of editting and extension of the Thread class.

Sin

2013-07-04 23:50:59

Didnt declare the thread properly:

Thread t = new Thread () {
drawMouse(g);
}
t.start();