QuestionQuestion

This programming project involves writing a program that draws two types of shapes, ovals and rectangles. This program consists of five classes and the Program Core.
The first class is the Shape class, which is an abstract class that extends the predefined Java class Rectangle. It should contain two instance variables, the color of the shape and whether the shape is solid or hollow. It should also contain a class (static) variable that keeps track of how many shapes have been created. It should have three instance methods, one class method, and one abstract method:
1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape:
a. Rectangle object that defines the dimensions and position of the shape
b. Color of the shape
c. Shape is solid or hollow
It should also update the number of shapes created from the beginning of the program.
2. An instance method named setColor that accepts the Graphics object as a parameter and sets the color for the next draw operation to the color of the current shape.
3. An instance method named getSolid that returns whether the shape is solid or hollow.
4. A class method named getNoOfShapes that returns the number of shapes created so far.
5. An abstract method named draw that accepts a Graphics object as a parameter.
The Shape class has two subclasses: Oval and Rectangular.
The first subclass is Oval. It should have the following two methods:
1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape, a Rectangle object that defines
a. Dimensions and position of the shape
b. Color of the shape
c. Shape is solid or hollow.
2. An overridden method draw that draws the Oval object on the Graphics object passed as a parameter.
The second subclass is Rectangular. It should have the following two methods:
1. A constructor that accepts three parameters for the purpose of initializing the characteristics of the shape, a Rectangle object that defines
a. Dimensions and position of the shape
b. Color of the shape
c. Shape is solid or hollow.
2. An overridden method draw that draws the Rectangular object on the Graphics object passed as a parameter.
The fourth class is named Drawing, which should extend the predefined Java class JPanel. It has one instance variable that contains the shape that is currently drawn. It should have three methods:
1. An overridden paintComponent method that draws the current shape on the Graphics object that is passed to it as a parameter. It should also draw the number of shapes that have been created thus far in the upper left corner.
2. An overridden getPreferredSize method that specifies the dimensions of the drawing panel as 200 pixels wide and 200 pixels high.
3. An instance method named drawShape that is passed the current shape to be drawn. It first checks whether the shape provided will completely fit within the panel. Assume for this assignment – no matter what dimensions are coded for the panel – the dimensions for the Panel are 200 pixels x 200 pixels. If not, it throws an OutsideBounds exception. Otherwise, it saves the shape in the corresponding instance variable. It then calls repaint to cause that shape to be drawn.
No additional public methods should be included in any of the above classes.
The fifth class named OutsideBounds should define a checked exception.

The combo-box for the Shape Type should allow two choices, either Rectangle or Oval. The combo-box for the Fill Type should also allow two choices, either Hollow or Solid. The combo-box for the Color should allow seven choices, Black, Red, Orange, Yellow, Green, Blue or Magenta.
Clicking the Draw button should first check whether any non-integer values have been entered in any of the fields that require integers. If so, an error message should be displayed in a JOptionPane window. Otherwise an appropriate Shape object should be created and passed to the drawShape method of the Drawing class. If that call results in an OutsideBounds exception being thrown, an appropriate error message should be displayed in a JOptionPane window. Note: only successful shapes that are displayed add to the count for Shapes.
It might be more user-friendly to add two additional buttons to the Geometric Drawing Window: (1) a Clear Field button for the width, height, and two coordinates test fields and (2) an Exit button to end the program.
Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class DrawShapes extends JFrame implements ActionListener {

    abstract static class Shape extends Rectangle {

       // instance variables
       protected Color color;
       protected boolean solid;
       private static int count;
       protected Rectangle rectangleObject;
       // parameterized constructor

       public Shape(Rectangle rectangle, Color color, boolean solid) {
            this.rectangleObject = rectangle;
            this.solid = solid;
            this.color = color;
            count++;
       }
       // method to set color of the graphics

       public void setColor(Graphics g) {
            this.color = g.getColor();
       }
       // return shape type is solid or hollow

       public boolean getSolid() {
            return this.solid;
       }
       // returns no of shapes draw

       public static int getNoOfShapes() {
            return count;
       }
       // abstract draw method

       public abstract void draw(Graphics g);
    }...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats