I am trying to change my System.in InputStream to instead take values from the terminal window but take values from a JEditorPane or JTextBox.
I have this to add the text to the new InputStream which has been declared.
Expand|Select|Wrap|Line Numbers
- GUI Class:
- public static InputStream consoleInputStream;
- ...
- sendButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String message = sendPane.getText();
- consoleInputStream = new ByteArrayInputStream(message.getBytes());
- sendPane.setText("");
- }
- });
Expand|Select|Wrap|Line Numbers
- System.setIn(GUI.consoleInputStream);
- ...
- public static String readLine() {
- String s = null;
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- try {
- s = in.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return s;
- }
What I have is a CLI applciation that runs off the User inputs from the terminal within Eclipse all I want to do is change main System.in input Stream to a Jtextbox output. I have the above working just in CLI (of course not setting System.setIn()...)
Any pointers would be awsome!