Question
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);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started