Placeholder

CMIS 242 Project 3 Draws Two Types of Shapes

$19.00

Description

The third programming project involves writing a program that draws two types of shapes, ovals and rectangles. This program consists of six classes. 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, the color of the shape and whether the shape is solid or hollow. It should also update the number of shapes created so far.
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. The first 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 the dimensions and position of the shape, the color of the shape and whether the 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 the dimensions and position of the shape, the color of the shape and whether the 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. 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 sixth class named Project3 should contain the main method. It should generate the GUI shown below:
Image transcription textGeometric Drawing – X Shape Type Oval Shape Drawing Fill Type Solid Color Red Width 100 Height 125 x
coordinate 40 y coordinate 30 Draw
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.
Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough different kinds of shapes to completely test the program.
SCREENSHOTS
SOLUTION
PAYMENT
CMIS 242 Project 3
CMIS 242 Draws Two Types of Shapes
CMIS 242 Geometric Drawing
CMIS 242 Project 3 Screenshot
The solution consists of:
All Java programs for this assignment.
A Netbeans Project in case you want to run theses programs on your computer.
Screenshots while running programs
Attachments [Move over files to preview content of those files]
CMIS242_Project_3.zip (229.98 KB)
Netbeans Project
CMIS242Project3
pom.xml
src
main
java
Drawing.java
OutsideBounds.java
Oval.java
Project3.java
Rectangular.java
Shape.java
test
java
target
classes
.netbeans_automatic_build
Drawing.class
OutsideBounds.class
Oval.class
Project3.class
Rectangular.class
Shape.class
generated-sources
annotations
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst
inputFiles.lst
test-classes
.netbeans_automatic_build
readme.txt
Screenshots
CMIS242-PROJECT-3-SCREENSHOT-1.png
CMIS242-PROJECT-3-SCREENSHOT-2.png
CMIS242-PROJECT-3-SCREENSHOT-3.png
CMIS242-PROJECT-3-SCREENSHOT-4.png
Source Code
Drawing.java
OutsideBounds.java
Oval.java
Project3.java
Rectangular.java
Shape.java
Preview Drawing.java
xxxxxx xxxxxxx(xxxxx xx) {
xxxxx = xx;
}
@xxxxxxxx
public void paintComponent(Graphics g) { // Always call super.paintComponent (g): super.paintComponent(g); // draw the number of shapes that have been created thus far in the upper left corner. g.drawString(String.valueOf(Shape.getNoOfShapes()), 10, 20); if (shape != null) { shape.setColor(g); shape.draw(g); } }
// the dimensions of the drawing panel as 200 pixels wide and 200 pixels high
@xxxxxxxx
xxxxxx xxxxxxxxx xxxxxxxxxxxxxxxx() {
xxxxxx xxx xxxxxxxxx(200, 200);
}
xxxxxx xxxx xxxxxxxxx() xxxxxx xxxxxxxxxxxxx {
Preview OutsideBounds.java
xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxxx {
xxxxxx xxxxxxxxxxxxx(xxxxxx xxxxxxxxxxxx) {
super(errorMessage); }
public OutsideBounds() { super(); }
}
Preview Oval.java
xxxxxx xxxx.xxx.*;
xxxxxx xxxxx xxxx xxxxxxx xxxxx {
public Oval(int x, int y, int width, int height, String color, String density) { super(x, y, width, height, color, density); }
@Override public void draw(Graphics g) {
xxxxxxxxx x = xxx xxxxxxxxx();
xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
} xxxx xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
}
Preview Project3.java
xxxxxx xxxxx.xxxxx.xxxxxx.xxxxxxxxxxxx;
xxxxxx xxxxx xxxxxxx3 xxxxxxx xxxxx.xxxxx.xxxxxx {
xxxxxxx xxxxxxx xxxxxxxxxxxx;
public Project3() {
initComponents();
shapePanel.setBorder(new TitledBorder(new LineBorder(Color.gray), “Shape Drawing”, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.CENTER, new Font(“SansSerif”, Font.BOLD, 13), Color.black));
}

@SuppressWarnings(“unchecked”)
//
//GEN-BEGIN:initComponents
private void initComponents() {

shapeTypeLabel = new javax.swing.JLabel();
fillTypeLabel = new javax.swing.JLabel();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxxxxxx();
Preview Rectangular.java
xxxxxx xxxx.xxx.*;
xxxxxx xxxxx xxxxxxxxxxx xxxxxxx xxxxx {
public Rectangular(int x, int y, int width, int height, String color, String density) { super(x, y, width, height, color, density); }
@Override public void draw(Graphics g) {
xxxxxxxxx x = xxx xxxxxxxxx();
xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
} xxxx xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
}
Preview Shape.java
//xxxxx xxxxxxxxxxx
xxxxxx xxxxx(xxx x, xxx x, xxx xxxxx, xxx xxxxxx, xxxxxx xxxxx, xxxxxx xxxxxxx) {
xxxxx(x, x, xxxxx, xxxxxx);
xxxxxxxxxxx++;
this.color = color; this.density = density; } //Sets color
public void setColor(Graphics g) { if (color.equalsIgnoreCase(“black”)) g.setColor(Color.BLACK); else if (color.equalsIgnoreCase(“red”)) g.setColor(Color.RED); else if (color.equalsIgnoreCase(“orange”)) g.setColor(Color.ORANGE);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxxxx”))
x.xxxxxxxx(xxxxx.xxxxxx);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxxx”))
x.xxxxxxxx(xxxxx.xxxxx);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxx”))
x.xxxxxxxx(xxxxx.xxxx);
Preview readme.txt
xx xxxx xxxxxxxx, xx xxxxxxxx xxxxxx xxxx xxx xxxxxxxx xxxxxxx.
xxx xxx xxxxxxx xxxxxxxx xx xxxx xxx xxx xxx xxxxxxxx xxxxxxx
xx
xxx xxx xxxx xxx xx xxxxxx xxxxxxx xxx xxxx xxxxxx xxxx xx “xxx” xxxxxx.
If you are using Netbean. Please choose Netbeans and JDK version as follow:
based on the NetBeans release documentation, here is a summary of the JDK versions you can use with all recent versions of NetBeans:
NetBeans 11.0: JDK 8, JDK 11, JDK 12
NetBeans 11.1: JDK 8, JDK 11, JDK 12
xxxxxxxx 11.2: xxx 8, xxx 11, xxx 13
xxxxxxxx 11.3: xxx 8, xxx 11, xxx 14
xxxxxxxx 12.0: xxx 8, xxx 11, xxx 14
Preview Drawing.java
xxxxxx xxxxxxx(xxxxx xx) {
xxxxx = xx;
}
@xxxxxxxx
public void paintComponent(Graphics g) { // Always call super.paintComponent (g): super.paintComponent(g); // draw the number of shapes that have been created thus far in the upper left corner. g.drawString(String.valueOf(Shape.getNoOfShapes()), 10, 20); if (shape != null) { shape.setColor(g); shape.draw(g); } }
// the dimensions of the drawing panel as 200 pixels wide and 200 pixels high
@xxxxxxxx
xxxxxx xxxxxxxxx xxxxxxxxxxxxxxxx() {
xxxxxx xxx xxxxxxxxx(200, 200);
}
xxxxxx xxxx xxxxxxxxx() xxxxxx xxxxxxxxxxxxx {
Preview OutsideBounds.java
xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxxx {
xxxxxx xxxxxxxxxxxxx(xxxxxx xxxxxxxxxxxx) {
super(errorMessage); }
public OutsideBounds() { super(); }
}
Preview Oval.java
xxxxxx xxxx.xxx.*;
xxxxxx xxxxx xxxx xxxxxxx xxxxx {
public Oval(int x, int y, int width, int height, String color, String density) { super(x, y, width, height, color, density); }
@Override public void draw(Graphics g) {
xxxxxxxxx x = xxx xxxxxxxxx();
xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
} xxxx xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
}
Preview Project3.java
xxxxxx xxxxx.xxxxx.xxxxxx.xxxxxxxxxxxx;
xxxxxx xxxxx xxxxxxx3 xxxxxxx xxxxx.xxxxx.xxxxxx {
xxxxxxx xxxxxxx xxxxxxxxxxxx;
public Project3() {
initComponents();
shapePanel.setBorder(new TitledBorder(new LineBorder(Color.gray), “Shape Drawing”, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.CENTER, new Font(“SansSerif”, Font.BOLD, 13), Color.black));
}

@SuppressWarnings(“unchecked”)
//
//GEN-BEGIN:initComponents
private void initComponents() {

shapeTypeLabel = new javax.swing.JLabel();
fillTypeLabel = new javax.swing.JLabel();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxx = xxx xxxxx.xxxxx.xxxxxx();
xxxxxxxxxx = xxx xxxxx.xxxxx.xxxxxxxxxx();
Preview Rectangular.java
xxxxxx xxxx.xxx.*;
xxxxxx xxxxx xxxxxxxxxxx xxxxxxx xxxxx {
public Rectangular(int x, int y, int width, int height, String color, String density) { super(x, y, width, height, color, density); }
@Override public void draw(Graphics g) {
xxxxxxxxx x = xxx xxxxxxxxx();
xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
} xxxx xx (xxxx.xxxxxxxx().xxxxxxxxxxxxxxxx(“xxxxxx”)) {
x.xxxxxxxx(x, x, xxxxx, xxxxxx);
}
Preview Shape.java
//xxxxx xxxxxxxxxxx
xxxxxx xxxxx(xxx x, xxx x, xxx xxxxx, xxx xxxxxx, xxxxxx xxxxx, xxxxxx xxxxxxx) {
xxxxx(x, x, xxxxx, xxxxxx);
xxxxxxxxxxx++;
this.color = color; this.density = density; } //Sets color
public void setColor(Graphics g) { if (color.equalsIgnoreCase(“black”)) g.setColor(Color.BLACK); else if (color.equalsIgnoreCase(“red”)) g.setColor(Color.RED); else if (color.equalsIgnoreCase(“orange”)) g.setColor(Color.ORANGE);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxxxx”))
x.xxxxxxxx(xxxxx.xxxxxx);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxxx”))
x.xxxxxxxx(xxxxx.xxxxx);
xxxx xx (xxxxx.xxxxxxxxxxxxxxxx(“xxxx”))
x.xxxxxxxx(xxxxx.xxxx);
Price: $19
You May Also Like:
CMIS 242 Project 1 Minimum Maximum and Average
CMIS 242 Project 2 Computes the Sales Tax
CMIS 242 Project 4 Manage a Real Estate Database

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.