這個簡單的程序應該能夠獲得標記百分比和批發成本,並計算出零售價格,我把一個行動監聽器放到了CALCULATE按鈕上,但是當我按下calculate按鈕時出現這個錯誤:在這個簡單的GUI程序中的錯誤
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:
For input string: "Enter the markup precentage"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at mm$CalcListerner.actionPerformed(mm.java:58)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
有人可以幫我解決這個問題嗎?
有人可以解釋這些錯誤信息,因爲我真的沒有得到任何的?
我的代碼是:
import javax.swing.*;
import java.awt.event.*;
public class mm extends JFrame {
private JTextField WholesaleCost;
private JTextField markupPresentage;
private JLabel WCost;
private JLabel MPrecentage;
private JButton button;
private JPanel pannel;
private final int Width = 250;
private final int height = 320;
public mm() {
setTitle("Retail Price Calculator");
setSize(Width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
buildPanel();
add(pannel);
}
private void buildPanel() {
WholesaleCost = new JTextField(10);
markupPresentage = new JTextField(10);
WCost = new JLabel("enter the Whole Sale cost");
MPrecentage = new JLabel("Enter the markup precentage");
button = new JButton("Calculate");
button.addActionListener(new CalcListerner());
pannel = new JPanel();
pannel.add(WholesaleCost);
pannel.add(markupPresentage);
pannel.add(WCost);
pannel.add(MPrecentage);
pannel.add(button);
}
private class CalcListerner implements ActionListener {
public void actionPerformed(ActionEvent e) {
String WSaleinput;
String MPres;
WSaleinput = WholesaleCost.getText();
MPres = MPrecentage.getText();
double Value = Double.parseDouble(WSaleinput) * (Double.parseDouble(MPres)/100);
JOptionPane.showMessageDialog(null, "Retail Price is " + Value);
}
}
public static void main(String[] args) {
mm x = new mm();
}
}
是出現什麼錯誤? – Vulcan 2012-08-15 02:48:10
我仍然沒有看到它。將它直接添加到您的問題中,因爲您可能沒有足夠的信譽來發布鏈接。 – Vulcan 2012-08-15 02:48:51
@Vulcan異常在線程 「AWT-EventQueue的-0」 java.lang.NumberFormatException:對於輸入字符串: 「輸入標記PRECENTAGE」 \t在sun.misc.FloatingDecimal.readJavaFormatString(未知來源) \t在java.lang中。 Double.parseDouble(來源不明) \t在毫米$ CalcListerner.actionPerformed(mm.java:58) \t在javax.swing.AbstractButton.fireActionPerformed(來源不明) \t在javax.swing.AbstractButton中的$ Handler.actionPerformed(未知源) \t at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) \t at javax.swing.DefaultButtonModel.setPressed(Unknown So urce) \t ...........更多 – ChawBawwa 2012-08-15 02:50:24