GUI中出现错误

时间:2016-10-02 20:56:22

标签: java swing user-interface

我下面有一段代码,是我课程的一部分。它限制用户输入特定范围内的数字。我只是想知道如何在我的GUI或控制台上添加错误信息,然后再说#34;请再试一次"如果用户输入了给定范围之外的数字。

        try { 
                FileWriter fileWriter = new FileWriter(fileName,true);
                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
                String A = textField.getText(); 
                String B = textField_1.getText(); 
                int myInt_2 = Integer.parseInt(B);
                int myInt = Integer.parseInt(A);
                if((myInt >= 0 && myInt <= 100) && ( myInt_2 >= 0 && myInt_2 <= 100)) { 
                    bufferedWriter.write(textField_2.getText()); 
                    bufferedWriter.write(",");
                    bufferedWriter.write(textField.getText()); 
                    bufferedWriter.write(',');
                    bufferedWriter.write(textField_1.getText());
                    bufferedWriter.write(',');
                    bufferedWriter.write(comboBox.getSelectedItem().toString());
                    bufferedWriter.write(',');
                    bufferedWriter.write(comboBox_1.getSelectedItem().toString());
                     // Always close files.
                    bufferedWriter.newLine();
                    bufferedWriter.close();
                }

        }catch (IOException ex) { 
            System.out.println("Error writing file" + fileName + "'" );

0 个答案:

没有答案