Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a question for this This is my Porject3 java file package Project3; import javax.swing.*; import javax.swing.event.AncestorListener; import Project3.Shape; import java.awt.*; import java.awt.event.*; import

I have a question for this

This is my Porject3 java file

package Project3;

import javax.swing.*;

import javax.swing.event.AncestorListener;

import Project3.Shape;

import java.awt.*;

import java.awt.event.*;

import java.util.ArrayList;

import java.util.List;

public class Project3 extends JFrame {

JButton computeSalesTax;

JPanel leftPanel;

JLabel shapeTypeLabel;

JLabel fillTypeLabel;

JLabel colorLabel;

JLabel widthLabel;

JLabel heightLabel;

JLabel xCoordinateLabel;

JLabel yCoordinateLabel;

JComboBox shapeCombo;

JComboBox fillCombo;

JComboBox colorCombo;

JTextField widthTxt;

JTextField heightTxt;

JTextField xCoordinateTxt;

JTextField yCoordinateTxt;

JPanel rightPanel;

JPanel bottomPanel;

JButton drawButton;

String shape[] = {"Rectangle", "Oval"};

String fill[] = {"Hollow", "Soild"};

String color[] = {"Black", "Red", "Orange", "Yellow", "Green", "Blue", "Magenta"};

//static Drawing drawWork = new Drawing();

Project3() {

JPanel space = new JPanel();

//Left Panel

leftPanel = new JPanel(new GridLayout(7,2,3,3));

shapeTypeLabel = new JLabel("Shape Type");

fillTypeLabel = new JLabel("Fill Type");

colorLabel = new JLabel("Color");

widthLabel = new JLabel("Width");

heightLabel = new JLabel("Height");

xCoordinateLabel = new JLabel("x coordinate");

yCoordinateLabel = new JLabel("y coordinate");

shapeCombo = new JComboBox(shape);

fillCombo = new JComboBox(fill);

colorCombo = new JComboBox(color);

widthTxt = new JTextField(10);

heightTxt = new JTextField(10);

xCoordinateTxt = new JTextField(10);

yCoordinateTxt = new JTextField(10);

leftPanel.setBounds(35,15,200,200);

leftPanel.add(shapeTypeLabel);

leftPanel.add(shapeCombo);

leftPanel.add(fillTypeLabel);

leftPanel.add(fillCombo);

leftPanel.add(colorLabel);

leftPanel.add(colorCombo);

leftPanel.add(widthLabel);

leftPanel.add(widthTxt);

leftPanel.add(heightLabel);

leftPanel.add(heightTxt);

leftPanel.add(xCoordinateLabel);

leftPanel.add(xCoordinateTxt);

leftPanel.add(yCoordinateLabel);

leftPanel.add(yCoordinateTxt);

//Right Panel

rightPanel = new JPanel(new GridLayout(1,1,2,2));

rightPanel.setBounds(260,15,200,200);

rightPanel.setBorder(BorderFactory.createTitledBorder("Shape Drawing"));

//Bottom Panel

bottomPanel = new JPanel(new GridLayout(1,1,2,2));

bottomPanel.setBounds(210,240,80,30);

drawButton = new JButton("Draw");

bottomPanel.add(drawButton);

//main Panel

setTitle("Geometric Drawing");

setResizable(false);

setSize(500,330);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setVisible(true);

add(leftPanel);

add(rightPanel);

add(bottomPanel);

add(space);

//drawButton.addActionListener(this);

}

class Rectangle {

String width = widthTxt.getText();

int widthValue = Integer.parseInt(width);

String height = heightTxt.getText();

int heightValue = Integer.parseInt(height);

String xCoordinate = xCoordinateTxt.getText();

int xCoordinateValue = Integer.parseInt(xCoordinate);

String yCoordinate = yCoordinateTxt.getText();

int yCoordinateValue = Integer.parseInt(yCoordinate);

public void comboControl() {

shapeCombo.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent ie){

String shape = (String)shapeCombo.getSelectedItem();

}

});

fillCombo.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent ie){

String fill = (String)fillCombo.getSelectedItem();

}

});

colorCombo.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent ie){

String color = (String)colorCombo.getSelectedItem();

}

});

}

}

public static void main(String[] args) {

Project3 MainFrame = new Project3();

}

}

************************ and this is my shape class*******************************************************

package Project3;

import java.awt.*;

import javax.swing.*;

abstract class Shape extends Rectangle{

Color colorCombo;

String fillCombo;

static int numberShape=0;

Rectangle r = new Rectangle();

Shape(Rectangle shape, Color color, String shapeSolidHollow){

numberShape++;

this.colorCombo = color;

this.fillCombo = shapeSolidHollow;

}

public void setColor(Graphics g){

//g.setColor(color);

if(colorCombo.equals("Black"))

g.setColor(Color.black);

else if(colorCombo.equals("Red"))

g.setColor(Color.red);

else if(colorCombo.equals("Orange"))

g.setColor(Color.orange);

else if(colorCombo.equals("Yellow"))

g.setColor(Color.yellow);

else if(colorCombo.equals("Green"))

g.setColor(Color.green);

else if(colorCombo.equals("Blue"))

g.setColor(Color.blue);

else if(colorCombo.equals("Magenta"))

g.setColor(Color.magenta);

}

String getSolid(){

return fillCombo;

}

int getNoOfShapes(){

return numberShape;

}

abstract void draw(Graphics g);

}

**********************I can't finish Oval, Rectangular, Drawing and OutsideBounds..**********************************************************

could you help with me finishing those class./?

package Project3;

import java.awt.*;

public class Oval extends Shape {

public Oval(Rectangle shape, Color color, String shapeSolidHollow) {

super(shape, color, shapeSolidHollow);

}

@Override

void draw(Graphics g)

{

// set the color to draw the shape in

g.setColor(colorCombo);

if (fillcombo == )

// draw the shape given the top left corner of the enclosing

// rectangle and the width and height

g.drawOval(widthValue,y,w,h);

g.fillOval(x, y, w,h);

}

}

image text in transcribed
Programming Project 3 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 predened 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: l. A constructor that accepts three parameters for the purpose of mi lizing the characteristics of the shape, a Rectangle object that denes 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 seccolor 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 gersol id that returns whether the shape is solid or hollow. A class method named geruoofsnapes that returns the number of shapes created so far. 5. An abstract method named draw that accepts a Graphics object as a parameter. .5 The shape class has two subclasses. The rst 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 denes 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 denes 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 comer. 2. An overridden getPreferredSize method that species 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 oucsidesounds 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 flh class named oursmelsonnds should dene a checked exception. The sixth class named projects should contain the main method. It should generate the GUI shown below: m Geometric Drlwlng D X sir-no type Fl TV! 00hr The combo-box for the shape type should allow two choices, either Rectangle or Ovalr The combo-box for the fill type should also allow two choices, either Hallow 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 rst 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 OutsideEounds exception being thrown, an appropriate error message should be displayed in a JOptionpane window. Be sure to follow good proyamming style. which means making all instance variables private. naming all constants and avoiding the duplication of code. Furthermore you must select enough dinerent kinds of shapes to completely test the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions