Thank you James:
You gave me the key to start. I wrote the appender. It's working fine. I appretiate your help.


import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

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

import org.apache.log4j.PatternLayout;
import org.apache.log4j.WriterAppender;


public class FrameAppender extends WriterAppender
{
   private JTextArea text;
   private JFrame frame;
   private OutputStreamWriter out;
public FrameAppender(JApplet applet)
   {
       this (applet , "Logging");
   }
public FrameAppender(JApplet applet, String title)
   {
       text = new JTextArea (15,50);
       text.setEditable(false);
       JScrollPane pane = new JScrollPane(text);
       frame  = new JFrame(title);
Container container = frame.getContentPane(); container.setLayout(new BorderLayout());
       container.add( pane , BorderLayout.CENTER);
frame.pack();
       frame.validate();
       frame.setVisible(true);
       //frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
out = new OutputStreamWriter(new JTextFieldOutputStream(this.text)); this.setWriter(out);
       this.setImmediateFlush(true);
this.setLayout(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)); frame.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
               frame.setVisible(false);    }
           public void windowClosed(WindowEvent e) {
               frame.setVisible(false);    }
        });
   }
private class JTextFieldOutputStream extends OutputStream{
       private JTextArea text;
       public JTextFieldOutputStream(JTextArea text){
           this.text=text;        }
public void write( int b ) throws IOException { text.append( String.valueOf( ( char )b ) ); } } }





James Stauffer wrote:

Write your own appender that passes the messages to the JFrame.

On 9/14/06, Mansour <[EMAIL PROTECTED]> wrote:

I am writing an applet, and hoping I can find a way to log to a JFrame.
My applet consists of many classes. So I 'll have to wrap them in a jar.
Is there a direct way to do this ??


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to