我有一個suposed推測體積計算器和結果回來爲「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);
}
和長度和寬度相同。 – Douglas 2011-03-30 13:15:28
@Douglas:我不確定我是否做得對。 [code]雙倍寬度,長度,深度,音量; length = Double.valueOf(toString()); width = Double.valueOf(toString()); depth = Double.valueOf(toString());字符串lengthString,widthString,depthString; lengthString = hotTubLengthText.getText(); widthString = hotTubWidthText.getText(); depthString = hotTubDepthText.getText(); [/ code] – Mike 2011-03-30 13:32:06
@Douglas:你如何在註釋中對代碼進行格式化,看起來像上面那樣?我不認爲我的通過是正確的。 – Mike 2011-03-30 13:33:33