i have a program that create the circle that move to random position with multithread, each thread will handle each circle movement. i know how to move a image but not a shape object.
g2d.draw(s.circle);
this line only paint the circle with spawn x y.
i’ve tried add
s.circle.getBounds().setLocation(s.x, s.y);
before
g2d.draw(s.circle);
but no effect
public void paint(Graphics g) {
if (draw == true) {
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
for (Star s : this.items) {
//g2d.drawImage(s.starImage, s.x, s.y, this);
g2d.draw(s.circle);
}
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
}
public void run() {
//if (!items.isEmpty()) {
while(true){
try {
for (Star s : this.items) {
s.move();
}
repaint();
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
}
}
//}
}
You will have to
Atleast the above worked for me when I was doing Java/2D – sorry for not posting the actual code, as it was long ago – but I’m sure you’ll figure it out 🙂