Question: Using the two below Java files, develop your own unique 2D graphic composed of 2D lines, Rectangles, Ellipses and Circles. Ideas such as a house,

Using the two below Java files, develop your own unique 2D graphic composed of 2D lines, Rectangles, Ellipses and Circles.

Ideas such as a house, barn, horse, flower, outdoor scene, or other stick figure comes to mind. The key is creating your own unique graphic using a free Java2D primitives.

Submit the Java source code, along with a less than one page description of your project including screen captures showing the successful running of your application.

Be sure to use the template code provided in the below two files as a starting point.

Grading Rubric:

-- Unique 2D graphic composed of at least 10 Java2D shapes (8 points)

- Documentation including description of project and screen captures (2 points)

Java file 1.

import javax.swing.JFrame;

public class CMSC325Driver extends JFrame { public CMSC325Driver() {

// Construct Class with Graphics Component CMSC325EX1 myExample = new CMSC325EX1(); // Add to JFrame add(myExample); // Set the Default Size and title setSize(400, 400); setTitle("CMSC 325 Java2D Template"); // Frame Default to be able to closd setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Center the Frame setLocationRelativeTo(null); }

public static void main(String[] args) { CMSC325Driver myDriver = new CMSC325Driver(); myDriver.setVisible(true); } }

Java File 2.

import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.awt.geom.Line2D; import javax.swing.JPanel;

public class CMSC325EX1 extends JPanel {

@Override public void paintComponent(Graphics g) { super.paintComponent(g); // Call methods to draw drawEllipse(g); drawLine(g); drawCircle(g); drawRect(g); } // Method to draw an Ellipse private void drawEllipse(Graphics g) {

Graphics2D g2d = (Graphics2D) g; Ellipse2D e = new Ellipse2D.Double(5, 10, 80, 130); g2d.setColor(Color.red); g2d.draw(e); } // Method to draw a Line private void drawLine(Graphics g) {

Graphics2D g2d = (Graphics2D) g; Line2D myLine = new Line2D.Double(150,150,150,250); g2d.setColor(Color.blue); g2d.draw(myLine); } // Method to draw a Circle private void drawCircle(Graphics g) {

Graphics2D g2d = (Graphics2D) g; Ellipse2D myCircle = new Ellipse2D.Double(200,100,75,75); g2d.setColor(Color.black); g2d.draw(myCircle); } // Method to draw a Rectangle private void drawRect(Graphics g) {

Graphics2D g2d = (Graphics2D) g; Rectangle2D myRect = new Rectangle2D.Double(300,30,50,50); g2d.setColor(Color.blue); g2d.draw(myRect); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!