我需要通过文本字段获取整数。
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个小时就会到期了
答案 0 :(得分:0)
将输入检索为字符串,然后将其转换为整数
Integer.ParseInt(String); //convert string to integer