1
我需要通過文本字段獲取整數。通過文本字段的輸入整數
textField_1 = new JTextField();
textField_1.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent e) {
//protected void processInputMethodEvent(InputMethodEvent e){
//InputMethodListener listener=inputMethodListener;
//op = textField_1.getText();
//inputnum = Integer.parseInt (op);
inputnum = Integer.parseInt(textField_1.getText());
textField.setText (String.format ("%d + %d = ", inputnum));
if(inputnum == numA){
score += 10;
Correctness.setText("That's Correct!");
correct = 1;
}
else{Correctness.setText("That's Incorrect!");
}
}
public void inputMethodTextChanged(InputMethodEvent arg0) {
//inputnum = console.nextInt();
}
}
}
這是這裏的代碼。所以我想能夠輸入一個整數,然後將其設置爲inputnum。我希望這裏有人能幫助我,因爲這一點,並在約4小時
你得到任何錯誤? – SacJn
使用'scanner'從用戶獲得輸入。 –
我沒有得到任何錯誤,我只是編輯了一個我試過的部分。它只是沒有得到任何輸入 – esmaj