java - ArrayList that contains circles that move -
public class second extends jpanel implements actionlistener { arraylist<ellipse2d.double> circles = new arraylist<ellipse2d.double>(); timer t = new timer(5, this); double x=0, y=0, velx=1, vely=1; circles.add(new ellipse2d.double(x,y,10,10)); public void paintcomponent(graphics g) { super.paintcomponent(g); graphics2d g2 = (graphics2d) g; for(ellipse2d.double k : circles){ g2.draw(k); } g2.fill(k); t.start(); } } public void actionperformed(actionevent e) { if (x < 0 || x > 560) { velx = -velx; } if (y <0 || y >360){ vely = -vely; } //x+= velx; y += vely; repaint(); }
i tried doing didnt work know how draw them , make them move think problem initializing arraylist
error: multiple markers @ line - syntax error on token "add", = expected after token - syntax error on token(s), misplaced construct(s) error add circle
you can execute add method inside method. should move part:
circles.add(new ellipse2d.double(x,y,10,10));
to method.
Comments
Post a Comment