У меня есть калькулятор, который рассчитывает объем и результаты возвращаются как «0»
JButton btnCalculateVlmn = new JButton("Calculate Hot Tub Volume");
btnCalculateVlmn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
double width = 0, length = 0, depth = 0, volume = 0;
String lengthString, widthString, depthString;
lengthString = hotTubLengthText.getText();
widthString = hotTubWidthText.getText();
depthString = hotTubDepthText.getText();
try
{
if (rdbtnRoundTub.isSelected())
{
volume = Math.PI * Math.pow(length / 2.0, 2) * depth;
}
else
{
volume = Math.PI * Math.pow(length * width, 2)
* depth;
}
DecimalFormat formatter = new DecimalFormat("#,###,###.###");
hotTubVolumeText.setText("" + formatter.format(volume));
}
catch (NumberFormatException e)
{
labelTubStatus
.setText("Fill in all fields");
}
}
});
btnCalculateVlmn.setBounds(20, 200, 180, 20);
hotTubs.add(btnCalculateVlmn);
JButton Exit = new JButton("Exit");
Exit.setBounds(220, 200, 80, 20);
Exit.addActionListener(this);
hotTubs.add(Exit);
}