Results 1 to 1 of 1
Thread: ConsoleWindow.init()
- 06-07-2009, 06:44 PM #1
ConsoleWindow.init()
The following code should display a window and write to:
System.setOut()
System.setErr()
1. I didn't find any log files or see anything displayed in the console, where do these methods write?
2. ConsoleWindow.init() has to be called from the main method, whilst somehow I am under the impression that this is called automatically.
3. ConsoleWindow.init() should call a window that displays debug messages. However, no such window appears.
Any ideas?
:confused:
NOTE 1:Core Java Vol I Fundamentals 8th Ed Pg.597 (511).Java Code:[B]ConsoleWindow.java1[/B] package homenetwork.bkr.training; import javax.swing.*; import java.io.*; /** A window that displays the bytes sent to System.out and System.err * */ public class ConsoleWindow { public void init() { JFrame frame = new JFrame(); frame.setTitle("Console Window"); final JTextArea output = new JTextArea(); output.setEditable(false); frame.add(new JScrollPane(output)); frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); frame.setLocation(DEFAULT_LEFT, DEFAULT_TOP); frame.setFocusableWindowState(false); frame.setVisible(true); //define a PrintStream that sends its bytes to the output text area PrintStream consoleStream = new PrintStream(new OutputStream() { public void write (int b) {} //never called public void write(byte[] b, int off, int len) { output.append(new String(b, off, len)); } }); //set both System.out and System.err to that stream System.setOut(consoleStream); System.setErr(consoleStream); } public static final int DEFAULT_WIDTH = 300; public static final int DEFAULT_HEIGHT = 200; public static final int DEFAULT_LEFT = 200; public static final int DEFAULT_TOP = 200; } [B]Test.java[/B] package homenetwork.bkr.training; public class Test { /** * @param args */ public static void main(String[] args) { ConsoleWindow window = new ConsoleWindow(); [B]window.init();[/B] } }
Similar Threads
-
Thread.sleep/Init?
By Moncleared in forum AWT / SwingReplies: 6Last Post: 01-24-2009, 12:31 AM -
design question comments wanted - essential class init()
By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 07-22-2008, 09:41 PM -
Applets (init, start, stop, destroy)
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:57 AM -
init() method displaying html
By reddzer in forum Java ServletReplies: 0Last Post: 11-10-2007, 07:20 PM -
[/WEB-INF/applicationContext-dao.xml]: Invocation of init method
By Heather in forum JDBCReplies: 2Last Post: 06-12-2007, 04:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks