I'm looking for direction on how to replace System.in
with an InputStream
that reads directly from a JTextField
.
So far my approach has pretty much been trial and error. I currently have;
JTextField input = new JTextField();
System.setIn(new InputStream() {
int ptr = 0;
@Override
public int read() throws IOException {
int c;
try {
c = input.getText().charAt(ptr);
}
catch (IndexOutOfBoundsException ioob) {
return 0;
}
ptr++;
return c;
}
});
This yields an NoSuchElementException
as in attempts to read when the input is empty and I assume can never find a delimiter.
What approach am I missing?