Question: Can you assist by adding these additional shapes to my code following the pattern below Triangle Rectangle Sphere Cube Cone Cylinder Torus package WK 4
Can you assist by adding these additional shapes to my code following the pattern below
Triangle
Rectangle
Sphere
Cube
Cone
Cylinder
Torus
package WKAdorante;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ShapeSelectorGUI extends JFrame
private JComboBox shapeComboBox;
private JComboBox sizeComboBox;
private JPanel displayPanel;
public ShapeSelectorGUI
setTitleShape Selector";
setSize;
setDefaultCloseOperationJFrameEXITONCLOSE;
setLayoutnew BorderLayout;
Shape selection
String shapes Circle "Square";
shapeComboBox new JComboBoxshapes;
shapeComboBox.addActionListenernew ShapeSelectionListener;
Size selection
String sizes Small "Medium", "Large";
sizeComboBox new JComboBoxsizes;
Control panel
JPanel controlPanel new JPanel;
controlPanel.addnew JLabelSelect Shape:";
controlPanel.addshapeComboBox;
controlPanel.addnew JLabelSelect Size:";
controlPanel.addsizeComboBox;
Display panel
displayPanel new JPanel
@Override
protected void paintComponentGraphics g
super.paintComponentg;
drawShapeg;
;
addcontrolPanel BorderLayout.NORTH;
adddisplayPanel BorderLayout.CENTER;
private void drawShapeGraphics g
String selectedShape String shapeComboBox.getSelectedItem;
String selectedSize String sizeComboBox.getSelectedItem;
int size getSizeFromSelectionselectedSize;
if CircleequalsselectedShape
gdrawOval size, size;
else if SquareequalsselectedShape
gdrawRect size, size;
private int getSizeFromSelectionString size
switch size
case "Small":
return ;
case "Medium":
return ;
case "Large":
return ;
default:
return ;
private class ShapeSelectionListener implements ActionListener
@Override
public void actionPerformedActionEvent e
displayPanel.repaint;
public static void mainString args
SwingUtilities.invokeLater
ShapeSelectorGUI gui new ShapeSelectorGUI;
gui.setVisibletrue;
;
public class Circle
private double radius;
public Circledouble radius
this.radius radius;
public double getRadius
return radius;
public void setRadiusdouble radius
this.radius radius;
public double getArea
return Math.PI radius radius;
package WKAdorante;
public class Square
private double side;
public Squaredouble side
this.side side;
public double getSide
return side;
public void setSidedouble side
this.side side;
public double getArea
return side side;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
