Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

42/18w/homework/circles/spec.pdf Part B: Circles (18 points): The second part of

ID: 3878683 • Letter: 4

Question

42/18w/homework/circles/spec.pdf Part B: Circles (18 points): The second part of this assignment asks you to turn in a file named circles java that draws a specific figure of grids of concentric circles. Your program should exactly repro- duce the image at left. This image has several levels of structure. There is a basic "subfigure" that occurs through- out, containing concentric circles inside it. The subfigure is repeated to form grids. The overall drawing panel is size 500 x 350. Its back- ground is cyan. The rectangular area behind the grids is green, and the background of the circles is yellow. The rec- tangles and circles are outlined in black. Each grid also has a pair of lines drawn across it in an "X" patterm. The seven figures on the panel should have the following properties. Description-Limposition- sizeofsubfigure-eirelespersubfigure trow seob 100 x 100 0, 0) (130, 25 10 10 NA N/A NA N/A 3 x 3 top-middle 100 x 100 (260,0)60 x 60 (360, 50)80x 80 48 x 48 24 x 24 72 x 72 top-right-1 - bottom-left bottom-middle (80, 200) bottom-right 170 2 x2 You can use the DrawingPanel's image comparison feature (File, Compare to W Different operating systems draw shapes in slightly different ways, so it is n between your outputand for your output. If there is no visible difference to the naked eye, your output is considered correct. (If your figure looks the same but has "thicker black lines, you may be re-drawing the same shapes multiple times.) Web File...), to check your output ormal to have some pixels different the expected output. You do not need to achieve 0 pixels difference to get full credit 1 of 2 ngPanel java F0F11 F12

Explanation / Answer

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Graphics2D;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

public class Circles extends JFrame {

private static final long serialVersionUID = 1L;

/**

* @param g Graphics Object

* @param backGround color of the parent object

* @param x coordinate for top left corner of the rectangle

* @param y coordinate for top left corner of the rectangle

* @param width of the figure

* @param height of the figure

* @param n number of circles

* @return

*/

private Graphics2D drawCircles(Graphics2D g, Color backGround, int x,

int y, int width, int height, int n) {

g.setColor(Color.yellow);

g.fillRoundRect(x, y, width, height, 100, 100);

g.setColor(Color.black);

g.drawRoundRect(x, y, width, height, 100, 100);

int d1 = width / (2 * n);

int d2 = width / n;

for (int i = 0; i < n - 1; i++) {

g.drawRoundRect(x + (i + 1) * d1, y + (i + 1) * d1, width - (i + 1)

* d2, height - (i + 1) * d2, 100, 100);

}

return g;

}

/**

* @param g Graphics Object

* @param backGround color of the parent object

* @param x coordinate for top left corner of the rectangle

* @param y coordinate for top left corner of the rectangle

* @param width of the rectangle

* @param height of the rectangle

* @param n number of subfigures

* @param rows

* @param cols

* @return

*/

private Graphics2D drawGrid(Graphics2D g, Color backGround, int x, int y,

int width, int height, int n, int rows, int cols) {

g.setColor(backGround);

g.fillRect(x, y, width * cols, height * rows);

g.setColor(Color.black);

g.drawRect(x, y, width * cols, height * rows);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

g = drawCircles(g, Color.yellow, x + (width * (i)), y + height

* (j), width, height, n);

}

}

// Draw Cross lines

g.drawLine(x, y, x + (width * cols), y + (height * rows));

g.drawLine(x, y + (height * rows), x + (width * cols), y);

return g;

}

public Circles() {

setSize(new Dimension(500, 400));

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

setBackground(new Color(0, 255, 255));

JPanel p = new JPanel() {

@Override

public void paintComponent(Graphics g) {

Graphics2D g2 = (Graphics2D) g;

// Top-Left figure

g2 = drawCircles(g2, Color.yellow, 0, 0, 100, 100, 10);

// Top-Middle figure

g2 = drawCircles(g2, Color.yellow, 130, 25, 100, 100, 10);

// Top-Middle-2 figure

g2 = drawCircles(g2, Color.yellow, 260, 0, 60, 60, 6);

// Top-Right figure

g2 = drawCircles(g2, Color.yellow, 360, 50, 80, 80, 4);

// Bottom-Left Figure

g2 = drawGrid(g2, Color.green, 10, 170, 48, 48, 4, 3, 3);

// Bottom-Middle Figure

g2 = drawGrid(g2, Color.green, 180, 200, 24, 24, 2, 5, 5);

// Bottom-Right Figure

g2 = drawGrid(g2, Color.green, 330, 170, 72, 72, 9, 2, 2);

}

};

setTitle("Circles");

this.getContentPane().add(p);

}

public static void main(String arg[]) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

// TODO Auto-generated method stub

new Circles();

}

});

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote