package G1.particles; import java.awt.Canvas; import java.awt.Graphics; import java.util.Random; import javax.swing.JApplet; /* Osnovne skracenice (shortcuts): * ctrl+space = Autocomplete - probajte cim pocnete da kucate nesto, pomaze! * ctrl+shift+F = Autoformat * ctrl+shift+O = Autoimport - svega sto nije ukljuceno, a referise se * ctrl+shift+G = Pretraga svih pojavljivanja obelezene reference * */ public class ParticleApplet extends JApplet { public ParticleApplet() { } @Override public void init() { // TODO Auto-generated method stub super.init(); setSize(500, 500); add(new ParticleCanvas(1000)); } } class ParticleCanvas extends Canvas { private Random randGen = new Random(); private Particle[] particles; public ParticleCanvas(int n) { setSize(500, 500); particles = new Particle[n]; for (int i = 0; i < n; i++) particles[i] = new Particle(randGen.nextInt(500), randGen.nextInt(500)); } @Override public void paint(Graphics g) { super.paint(g); for (Particle p : particles) { g.fillOval(p.getX(), p.getY(), 5, 5); } } } class Particle { private int x; private int y; public Particle(int x, int y) { super(); this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } }