Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过文本字段输入整数_Java_User Interface_Events - Fatal编程技术网

Java 通过文本字段输入整数

Java 通过文本字段输入整数,java,user-interface,events,Java,User Interface,Events,我需要通过文本字段得到一个整数 textField_1 = new JTextField(); textField_1.addInputMethodListener(new InputMethodListener() { public void caretPositionChanged(InputMethodEvent e) { //protected void processInputMethodEvent(InputMethodEvent e){

我需要通过文本字段得到一个整数

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小时后到期

将输入检索为字符串,然后将其转换为整数

Integer.ParseInt(字符串)//将字符串转换为整数

将输入检索为字符串,然后将其转换为整数

Integer.ParseInt(字符串)//将字符串转换为整数

使用
扫描仪
从用户处获取输入。我没有收到任何错误,我只是编辑了一个我尝试过的部分。它只是没有得到任何输入使用
扫描仪
从用户那里获得输入。我没有得到任何错误,我只是编辑了一个我尝试过的部分。它只是没有得到任何输入