Now I am having problems with the actionListener. How do I get it to work so that the volume takes all variables?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.awt.Container;
public class rectangularSolid extends JApplet implements ActionListener {
public void init() {
String in = JOptionPane.showInputDialog("1(volume),2(surface area),3(diagonal)");
int input = Integer.parseInt(in);
switch(input) {
case 1:
JLabel prompt;
JLabel prompt2;
JLabel prompt3;
JLabel prompt4;
Container c = getContentPane();
c.setLayout(new FlowLayout());
JTextField insert;
JTextField insert2;
JTextField insert3;
JTextField insert4;
prompt = new JLabel("enter length");
insert = new JTextField(10);
c.add(prompt);
c.add(insert);
prompt2 = new JLabel("enter width");
insert2 = new JTextField(10);
c.add(prompt2);
c.add(insert2);
prompt3 = new JLabel("enter height");
insert3 = new JTextField(10);
c.add(prompt3);
c.add(insert3);
insert.addActionListener(this);
insert2.addActionListener(this);
insert3.addActionListener(this);
break;
case 2:
JTextArea outputArea;
outputArea = new JTextArea(2,10);
Container c1 = getContentPane();
c1.add(outputArea);
DecimalFormat twoDigits = new DecimalFormat("0.00");
String sa = JOptionPane.showInputDialog("enter length");
double length2 = Double.parseDouble(sa);
String w2 = JOptionPane.showInputDialog("enter width");
double width2 = Double.parseDouble(w2);
String h2 = JOptionPane.showInputDialog("enter height");
double height2 = Double.parseDouble(h2);
String output = "";
output = (" Surface area = "
+ twoDigits.format(surfaceArea(length2,width2,height 2)));
outputArea.setText(output);
JOptionPane.showMessageDialog(null,outputArea,null ,
JOptionPane.INFORMATION_MESSAGE);
break;}
}
public void actionPerformed(ActionEvent e ) {
double length = Double.parseDouble(e.getActionCommand() );
double width = Double.parseDouble(e.getActionCommand());
double height = Double.parseDouble(e.getActionCommand());
showStatus("Volume is " + volume ( length, width, height ) );
}
public double volume(double length, double width, double height) {
return length * width * height;
}
public double surfaceArea(double length2, double width2, double height2) {
return ( 2 * length2 * width2 + 2 * length2 * height2 + 2 * width2 * height2);
}
}