So I found this really cool code here:
http://www.exampledepot.com/egs/java...#comment-50625
import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; public class Console extends JFrame { PipedInputStream piOut; PipedInputStream piErr; PipedOutputStream poOut; PipedOutputStream poErr; JTextArea textArea = new JTextArea(); public Console() throws IOException { // Set up System.out piOut = new PipedInputStream(); poOut = new PipedOutputStream(piOut); System.setOut(new PrintStream(poOut, true)); // Set up System.err piErr = new PipedInputStream(); poErr = new PipedOutputStream(piErr); System.setErr(new PrintStream(poErr, true)); // Add a scrolling text area textArea.setEditable(false); textArea.setRows(20); textArea.setColumns(50); getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); pack(); setVisible(true); // Create reader threads new ReaderThread(piOut).start(); new ReaderThread(piErr).start(); } class ReaderThread extends Thread { PipedInputStream pi; ReaderThread(PipedInputStream pi) { this.pi = pi; } public void run() { final byte[] buf = new byte[1024]; try { while (true) { final int len = pi.read(buf); if (len == -1) { break; } SwingUtilities.invokeLater(new Runnable() { public void run() { textArea.append(new String(buf, 0, len)); // Make sure the last line is always visible textArea.setCaretPosition(textArea.getDocument().getLength()); // Keep the text area down to a certain character size int idealSize = 1000; int maxExcess = 500; int excess = textArea.getDocument().getLength() - idealSize; if (excess >= maxExcess) { textArea.replaceRange("", 0, excess); } } }); } } catch (IOException e) { } } } }
This code basically makes my program display in a console box from what I can tell. I was wondering if anyone knows how to make it so it has a input like scanner too?
Maybe its too much to bother you guys for, but I really want to use this and I can't do it myself since I hardly understand what its doing heh..
But seriously any help would be awesome.