Total members 11893 |It is currently Sat Nov 09, 2024 3:50 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





The following class is simple idea which you can have a text area to log events in your desktop application , as you may notice that the textArea ref is final and static , so we will have one textarea all over the application process.

Code:


import java
.util.Date;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class GUILogger {

    private static GUILogger logger = null;
    private static final JTextArea textArea = new JTextArea(7, 50);
    private static final JScrollPane TextAreaScroll = new JScrollPane
(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    private GUILogger() {
    }

    public static GUILogger getInstance() {
        if (logger == null) {
            logger = new GUILogger();
        }
        return logger;
    }

    public void logInfo(String info) {
        textArea.append("\n" + new Date() + ": " + info);
    }

    public static GUILogger getLogger() {
        return logger;
    }

    public static void setLogger(GUILogger logger) {
        GUILogger.logger = logger;
    }

    public static JScrollPane getTextAreaScroll() {
        return TextAreaScroll;
    }

    public static JTextArea getTextArea() {
        return textArea;
    }
}
 


Add it to a panel .
Code:

import java
.awt.BorderLayout;
import javax.swing.JPanel;

public class 
LogPanel extends JPanel {

    private 
GUILogger gUILogger GUILogger.getInstance();

    public 
LogPanel() {

        
add(gUILogger.getTextAreaScroll());
    }
}
 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : GUI logger
 Asynchronous Logger using Java     -  
 Java extending org.apache.log4j.Logger     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com