Problem Statement For this assignment you will create your own, original work of
ID: 3694726 • Letter: P
Question
Problem Statement For this assignment you will create your own, original work of abstract art! This work of art will be created by drawing certain shapes in random sizes, colors, and locations. The basic shapes are: Recall that methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can be called as many times as needed without rewriting the code each time. Each shape above will be implemented in its own method. Finally, we will use documentation comments for each method. These comments will allow you to generate HTML documents similar to the Java APIs that we have seen. Below is an example of a possible solution. Your picture will have the same basic components, but need not look exactly like this one.Explanation / Answer
import java.awt.*; import java.applet.*; public class Checkerboard extends Applet { /* This applet draws a red-and-black checkerboard. It is assumed that the size of the applet is 160 by 160 pixels. */ public void paint(Graphics g) { int row; // Row number, from 0 to 7 int col; // Column number, from 0 to 7 int x,y; // Top-left corner of square for ( row = 0; row < 8; row++ ) { for ( col = 0; col < 8; col++) { x = col * 20; y = row * 20; if ( (row % 2) == (col % 2) ) g.setColor(Color.red); else g.setColor(Color.black); g.fillRect(x, y, 20, 20); } } // end for row } // end paint() } // end class import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JFrame; public class RectSpiral extends JPanel { public void paintComponent(Graphics g) { int width = getSize().width; int height = getSize().height; int widthCenter = width / 2; int heightCenter = height / 2; for (int i = 0; i < 4 ; i++) { g.drawLine(widthCenter + (20 * i), heightCenter + (20 * i), widthCenter + (20 * i), heightCenter + 20 + (20 * i)); g.drawLine(widthCenter + (20 * i), heightCenter + 20 + (20 * i), widthCenter - 20 - (20 * i), heightCenter + 20 + (20 * i)); g.drawLine(widthCenter - 20 - (20 * i), heightCenter + 20 + (20 * i), widthCenter - 20 - (20 * i), heightCenter - 20 - (20 * i)); g.drawLine(widthCenter - 20 - (20 * i), heightCenter - 20 - (20 * i), widthCenter + 20 + (20 * i), heightCenter - 20 - (20 * i)); } } public static void main(String[] args) { RectSpiral panel = new RectSpiral(); JFrame application = new JFrame(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add(panel); application.setSize(300, 300); application.setVisible(true); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.