I have created a console Application and now I'm starting to convert it into a swing Application. I have one question and I searched many times for an answer but I didn't find any.
My application has an class which validates the input of the user and also if the input is wrong it gives a error msg into console. So what I try to do is, I have an Jtextfield and validate this input, if the input is wrong it should give me the error msg.
That's my Input class where the User is allowed to write
public class Input {
private static BufferedReader eingabe = new BufferedReader(new InputStreamReader(System.in));
private Output output = new Output();
private static String captureText() throws Exception {
return eingabe.readLine();
}
public String formatInput() {
boolean again = true;
while (again) {
try {
String format = captureText();
if (!format.equalsIgnoreCase("Y") && !format.equalsIgnoreCase("N")) {
again = true;
throw new Exception();
}
again = false;
return format;
} catch (Exception e) {
this.output.formatInputWrong();
}
}
return null;
}
}
That's my output class method
void formatInputWrong() {
System.out.print("\nThe Format Input is wrong.");
}
I just want to know can I use the Validation of the Input class or should I create a special class for the swing input validation because I know I can take out the Input of the JTextfield?