我需要通过文本字段获取一个整数。
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个小时就要到了。
发布于 2015-10-23 17:29:55
检索字符串形式的输入,然后将其转换为整数
Integer.ParseInt(String); //convert string to integer
https://stackoverflow.com/questions/33298581
复制相似问题