Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:20 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: GUI logger
PostPosted: Sat Nov 27, 2010 10:58 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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());
    }
}
 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Java extending org.apache.log4j.Logger

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team