Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 cshape; private JComboBox cfillType; private JComboBox ccolor; private JTextField twidth; private JTextField theight; private JTextField tx; private JTextField ty; private JButton draw; private JPanel panel; int shapeWidth; int shapeHeight; int shapeX; int shapeY; public Drawing() { setSize(600,400); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null); setLocationRelativeTo(null); setTitle("Geometric Drawing"); shape=new JLabel("Shape Type"); fillType=new JLabel("Fill Type"); color=new JLabel("Color"); width=new JLabel("Width"); height=new JLabel("Height"); x=new JLabel("x coordinate"); y=new JLabel("y coordinate"); printCount=new JLabel("1"); cshape=new JComboBox<>(new String[] {"Oval","Rectangle"}); cfillType=new JComboBox<>(new String[] {"Solid","Hollow"}); ccolor=new JComboBox<>(new String[] {"Black","Red","Orange","Yellow","Green","Blue","Magenta"}); twidth=new JTextField(); theight=new JTextField(); tx=new JTextField(); ty=new JTextField(); draw=new JButton("Draw"); panel=new JPanel(); panel.setBorder(BorderFactory.createTitledBorder("Shape Drawing")); add(shape); add(fillType); add(color); add(width); add(height); add(x); add(y); add(printCount); add(cshape); add(cfillType); add(ccolor); add(twidth); add(theight); add(tx); add(ty); add(draw); add(panel); shape.setBounds(20, 20, 100, 30); fillType.setBounds(20, 55, 100, 30); color.setBounds(20, 90, 100, 30); width.setBounds(20, 125, 100, 30); height.setBounds(20, 160, 100, 30); x.setBounds(20, 195, 100, 30); y.setBounds(20, 230, 100, 30); printCount.setBounds(285, 40, 20, 30); cshape.setBounds(140, 20, 100, 30); cfillType.setBounds(140, 55, 100, 30); ccolor.setBounds(140, 90, 100, 30); twidth.setBounds(140, 125, 100, 30); theight.setBounds(140, 160, 100, 30); tx.setBounds(140, 195, 100, 30); ty.setBounds(140, 230, 100, 30); draw.setBounds(230, 280, 80, 30); panel.setBounds(270, 20, 300, 250); draw.addActionListener(this); setVisible(true); } // end public Drawing() private void checkException() { try { shapeWidth=Integer.parseInt(twidth.getText()); shapeHeight=Integer.parseInt(theight.getText()); shapeX=Integer.parseInt(tx.getText()); shapeY=Integer.parseInt(ty.getText()); if((shapeWidth+shapeX)>300 || (shapeHeight+shapeY)>250 || shapeWidth<0 || shapeheight<0 shapex<0 shapey<0) throw new outsidebounds("shape coordinates not in sized panel...!!!"); }catch(outsidebounds o) { joptionpane.showmessagedialog(null, o.getmessage()); }catch(exception e) "please enter valid dimension and coordinates...!!!"); }>

// 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

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

Students also viewed these Databases questions