Normally, When I want to draw something I do this:
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.fillRect(3, 7, 10, 10);
g.fillOval(10,10,10,10);
}
But If I follow the way I did above I only have a limited number of shapes(Rect, Oval and nothing else).
I’m looking for something different, for example, whenever a method addStuff(x, y) has called, it draws “Stuff” automatically at the coordinate x and y.
I used to do this with the acm package and it was easy. Just like the code below.
for (int i = 0; i < NCIRCLES; i++) {
double r = rgen.nextDouble(MIN_RADIUS, MAX_RADIUS);
double x = rgen.nextDouble(0, getWidth() - 2 * r);
double y = rgen.nextDouble(0, getHeight() - 2 * r);
GOval circle = new GOval(x, y, 2 * r, 2 * r);
circle.setFilled(true);
circle.setColor(rgen.nextColor());
add(circle);
}
As you can see, I can add as many circles as I want with the code above. But now I’m struck with doing the same thing without using acm package. I’m really new in Java game programming. Anyone have any idea ???