Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1000824 // Redirecting stdout+stderr to LogView test

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (131L/1K/5K).

!747
!actionListener {

!721 // thread {
!x1000805 // awt {

main {
  static LogView logView;
  
  !include #1000820 // LogView

  psvm {
    awt {
      JFrame frame = new JFrame("LogView Test");
    
      logView = new LogView;
      
      redirectStdOutAndErrTo(logView);

      //logView.println("Hello Agnes");
      //logView.println("Hello Julia");
  
      frame.add(logView);
      frame.setBounds(100, 100, 500, 400);
      print("Showing");
      frame.setVisible(true);
      exitOnFrameClose(frame);
      print("Done showing");
      
      logView.println("Hello Julia");
      print("yup");
    }
  }
  
  static void redirectStdOutAndErrTo(final LogView lg) {
    OutputStream outputStream = new OutputStream() {
      public void write(int b) {
        try {
          lg.print(new String(new byte[] {(byte) b}, "UTF-8")); // This is crap
        } catch (UnsupportedEncodingException e) {}
      }
      
      @Override
      public void write(byte[] b, int off, int len) {
        try {
          lg.print(new String(b, off, len, "UTF-8")); // This is crap
        } catch (UnsupportedEncodingException e) {}
      }
    };
    
    PrintStream ps = new PrintStream(outputStream, true);
    System.setOut(ps);
    System.setErr(ps);
  }
}

Author comment

Began life as a copy of #1000821

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, iveijnkanddl, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1071 stefan OK! 2015-08-28 20:38:41

add comment

Snippet ID: #1000824
Snippet name: Redirecting stdout+stderr to LogView test
Eternal ID of this version: #1000824/1
Text MD5: ae6386a32d3ed017888401e222c2844b
Transpilation MD5: b5fc5f09db73fbb7de41da64f95aa2c6
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-28 20:37:56
Source code size: 1313 bytes / 54 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 868 / 882
Referenced in: [show references]