So I have this assignment I have been working on for a class, but having trouble trying to duplicate the shapes within the boundaries I have set. The code is below for what I already have and a picture for what I need. I have the circles and shapes down, but just need a little insight on how to repeat them on the second row like the picture. Any help would be the best!!!
}
public static void drawBasic(Graphics g, int x, int y,
int circles, int size) {
int gap=size/(2*circles);
g.setColor(Color.RED);
g.fillOval(x, y, size, size);
g.setColor(Color.BLACK);
for (int i=0; i<circles; i++) {
g.drawOval(x+(i*gap), y+(i*gap), size-(2*i*gap), size-(2*i*gap));
}
}
public static void drawGrid(Graphics g, int x, int y, int circles, int size, int rows){
g.setColor(Color.LIGHT_GRAY);
g.fillRect(x, y, size*rows, size*rows);
g.setColor(Color.RED);
g.drawRect(x, y, size*rows, size*rows);
for(int i=0; i<rows; i++) {
drawBasic(g, x+(i*size), y, circles, size);
Surely you should have a class that extends JComponent that draws the shape and you create an instances of it with certain parameters like num circles. Then you add these components to a JPanel. You may also want to add the square grid groupings to their own JPanel with a border and background colour set and a GridLayout and add this JPanel to your root panel.
Bookmarks