Source Code : Standard Err and Output Windows

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Standard Err and Output Windows

 

import java.io.OutputStream;
import java.io.PrintStream;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

public class StdErrOutWindows {
  JTextArea outArea = new JTextArea(20, 50), errArea = new JTextArea(20, 50);;

  public StdErrOutWindows() {
    JScrollPane pain = new JScrollPane(outArea);
    JFrame outFrame = new JFrame("out");
    outFrame.getContentPane().add(pain);
    outFrame.setVisible(true);
    
    pain = new JScrollPane(errArea);
    JFrame errFrame = new JFrame("err");
    errFrame.getContentPane().add(pain);
    errFrame.setLocation(errFrame.getLocation().x + 20, errFrame.getLocation().y + 20);
    errFrame.setVisible(true);

    System.setOut(new PrintStream(new JTextAreaOutputStream(outArea)));
    System.setErr(new PrintStream(new JTextAreaOutputStream(errArea)));
  }

  public static void main(String[] args) {
    new StdErrOutWindows();
    System.out.println("test to out");
    try {
      throw new Exception("Test exception");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public class JTextAreaOutputStream extends OutputStream {
    JTextArea ta;

    public JTextAreaOutputStream(JTextArea t) {
      super();
      ta = t;
    }

    public void write(int i) {
      ta.append(Character.toString((char)i));
    }

    public void write(char[] buf, int off, int len) {
      String s = new String(buf, off, len);
      ta.append(s);
    }

  }

}

   
  

Thank with us