weightField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((c >= '0') && (c <= '9') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
getToolkit().beep();
e.consume();
}
if(serviceTypeComboBox.getSelectedIndex() == 0 && letterTypeComboBox.getSelectedIndex() == 0){
priceField.setText(Integer.toString((Integer.parseInt(weightField.getText())/500) * 23000));
}else if(serviceTypeComboBox.getSelectedIndex() == 0 && letterTypeComboBox.getSelectedIndex() == 1){
priceField.setText(Integer.toString((Integer.parseInt(weightField.getText())/500) * 40000));
}else if(serviceTypeComboBox.getSelectedIndex() == 1 && letterTypeComboBox.getSelectedIndex() == 0){
priceField.setText(Integer.toString((Integer.parseInt(weightField.getText())/500) * 11000));
}else if(serviceTypeComboBox.getSelectedIndex() == 1 && letterTypeComboBox.getSelectedIndex() == 1){
priceField.setText(Integer.toString((Integer.parseInt(weightField.getText())/500) * 25000));
}
}});
我不知道为什么我在键入键时收到 java.lang.NumberFormatException ...:线程“AWT-EventQueue-0”中的异常 java.lang.NumberFormatException:对于输入字符串:“”