Question
Can't seem to get this running in Netbeans. Any help would be appreciated.. package project3; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import javax.swing.BorderFactory; import javax.swing.JComboBox;
Can't seem to get this running in Netbeans. Any help would be appreciated..
package project3;
import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import javax.swing.BorderFactory; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class PROJECT3 {
public abstract class Shape extends Rectangle { private static final long serialVersionUID = 1L; public String color; public String shape; int count; public Shape(Point p, Dimension d, String color, String shape) { super(p, d); this.color = color; this.shape = shape; count++; } // end public Shape 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); else if(color.equalsIgnoreCase("yellow")) g.setColor(Color.YELLOW); else if(color.equalsIgnoreCase("green")) g.setColor(Color.GREEN); else if(color.equalsIgnoreCase("blue")) g.setColor(Color.BLUE); else if(color.equalsIgnoreCase("magenta")) g.setColor(Color.MAGENTA); } // end public void setColor(Graphics g) public String getSolid() { return shape; } // end public String getSolid public int getNoOfShapes() { return count; } // end public int getNoOfShapes public abstract void draw(Graphics g); } // end public abstract class Shape extends Rectangle public class Rectangular extends Shape { private static final long serialVersionUID = 1L; public Rectangular(Point p, Dimension d, String color, String shape) { super(p, d, color, shape); } // end public Rectangular @Override public void draw(Graphics g) { if(getSolid().equalsIgnoreCase("hollow")) g.drawRect((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); else if(getSolid().equalsIgnoreCase("solid")) g.fillRect((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); } // end public void draw(Graphics g) } // end public class Rectangular extends Shape
public class Oval extends Shape { private static final long serialVersionUID = 1L; public Oval(Point p, Dimension d, String color, String shape) { super(p, d, color, shape); } // end public Oval @Override public void draw(Graphics g) { if(getSolid().equalsIgnoreCase("hollow")) g.drawOval((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); else if(getSolid().equalsIgnoreCase("solid")) g.fillOval((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); } //end public void draw(Graphics g) } // end public class Oval extends Shape
public static class Drawing extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; Shape s = null; int NoOfShapes = count; private JLabel shape; private JLabel fillType; private JLabel color; private JLabel width; private JLabel height; private JLabel x; private JLabel y; private JLabel printCount; private JComboBox // public static Shape Oval(Point p, Dimension d, String selectedItem, String selectedItem2) { // return null; // } @Override public void paint(Graphics g) { try { // print count of shapes printCount.setText(getNoOfShapes()+""); //Shape. super.paintComponents(g); s.setColor(g); s.draw(g); }catch(Exception e) {} } // end public void paint(Graphics g) @Override public void actionPerformed(ActionEvent arg0) { try { checkException(); Point p=new Point(shapeX+270, shapeY+50); Dimension d=new Dimension(shapeWidth, shapeHeight); if(((String) cshape.getSelectedItem()).equalsIgnoreCase("Rectangular")) s= Rectangular(p, d,(String)ccolor.getSelectedItem(), (String)cfillType.getSelectedItem()); else s= Oval(p, d,(String)ccolor.getSelectedItem(), (String)cfillType.getSelectedItem()); repaint(); // call paint() method }catch(Exception e) {} } // end public void actionPerformed(ActionEvent arg0) public static void main(String[] args) { new Drawing(); } // end public static void main(String[] args) } public static class OutsideBounds extends Exception { private static final long serialVersionUID = 1L; public OutsideBounds(String errorMessage) { // call super class parameterized constructor super(errorMessage); } // end public OutsideBounds(String errorMessage) } // end public static class OutsideBounds extends Exception } // end public class PROJECT3
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