import javax.swing.*; import java.awt.event.*; import java.awt.*; /** * The Geometry DEMO * * @author Luis Fierro * @version 4/1/2014 */ public class GeometryCalculatorDemo extends JFrame { private JPanel panel; //a holding panel private JLabel messageLabel; // a message to the user private JLabel textLabel1; //show what radius, length or base depending on user choice private JLabel textLabel2; //shows width or height depending on user choice private JTextField measurement1Text; private JTextField measurement2Text; private JRadioButton circButton; private JRadioButton rectButton; private JRadioButton triButton; private JRadioButton endButton; private ButtonGroup radioButtonGroup; private final int WINDOW_WIDTH = 400; private final int WINDOW_HEIGHT = 100; /** * Constructor for objects of class GeometryCalculator */ public static void main (String []args) { // initialise instance variables char again; //do I run again int choice; //find out what to calculate do { switch( e.getSource()) { case circButton: textLabel1.setText("Enter the radius"); circle(); break; case rectButton: rectangle(); break; case triButton: triangle(); break; case endButton: JOptionPane.showMessageDialog(null, "Bye-bye!!"); break; } } while (choice !=4); } /** * */ public void getMenuChoice() { //set the title setTitle ("Geometry Calculator"); //set the size of the window setSize (WINDOW_WIDTH, WINDOW_HEIGHT); //actions for the close button setDefaultCloseOperation(JFrane.EXIT_ON_CLOSE); //build a pane buildPane(); //add the pane to the frame add(panel); //show window setVisible(true); } private void buildPane() { messageLabel=new JLabel("Select a shape to calculate the area: "); textLabel1=new JLabel(""); textLabel2=new JLabel(""); measurement1Text= new JTextField(4); measurement2Text= new JTextField(4); circButton=new JRadioButton("Circle"); rectButton=new JRadioButton("Rectangle"); triButton=new JRadioButton("Triangle"); endButton=new JRadioButton("End Program"); //group the buttons radioButtonGroup= new ButtonGroup(); radioButtonGroup.add(circButton); radioButtonGroup.add(rectButton); radioButtonGroup.add(triButton); radioButtonGroup.add(endtButton); } public static void circle() { double rad; String input; input = measurement1Text.getText; rad = Double.parseDouble(input); JOptionPane.showMessageDialog(null, Geometry.circArea(rad)); } public static void rectangle() { double len; double wid; String input; String input2; input = measurement1Text.getText; leng = Double.parseDouble(input); input2 = measurement2Text.getText; wid = Double.parseDouble(input2); JOptionPane.showMessageDialog(null, Geometry.rectArea(len,wid)); } public static void triangle() { double base; double heig; String input; String input2; input = measurement1Text.getText; base = Double.parseDouble(input); input2 = measurement2Text.getText; heig = Double.parseDouble(input2); JOptionPane.showMessageDialog(null, Geometry.triArea(base, heig)); } }