package particles; import java.util.Random; import javax.swing.RepaintManager; /* Klasa Thread ima metod run koji definise nacin na koji se * ona pokrece */ public class Particle extends Thread { private Random randGen = new Random(); private int x; private int y; private ParticlesPanel panel; public Particle(ParticlesPanel panel) { super(); this.panel=panel; this.x = randGen.nextInt(ParticlesGUI.WIDTH); this.y = randGen.nextInt(ParticlesGUI.HEIGHT); start(); } public int getX() { return x; } public int getY() { return y; } public void move() { int dx=(randGen.nextInt(3) - 1); int dy=(randGen.nextInt(3) - 1); x += dx; y += dy; } @Override public void run() { super.run(); while (true) { move(); panel.repaint(); try { Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }