轉換用戶的米英尺和英寸與添加字符串和int值在一個JTextField中
// following format (16ft. 4in.). Disable the button so that
// the user is forced to clear the form.
輸入的問題是,我不知道如何把字符串和int值在一個文本字段如果else語句
private void ConversionActionPerformed(ActionEvent e)
{
String s =(FourthTextField.getText());
int val = Integer.parseInt(FifthTextField.getText());
double INCHES = 0.0254001;
double FEET = 0.3048;
double meters;
if(s.equals("in"))
{
FourthTextField.setText(" " + val*INCHES + "inch");
}
else if(s.equals("ft"))
{
FourthTextField.setText(" " +val*FEET + "feet");
}
}
比我如何能在他們設定爲能夠加入一個JTextField
字符串和int值?
'FourthTextField'請給予控件有意義的名稱。還請學習類的常用[Java命名約定](http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#73307)(具體用於名稱的情況)方法和屬性名稱並一致使用它。 – 2013-02-20 04:36:04