Switch to full style
General Java code examples
Post a reply

Re: Read your gmail using Java code

Wed Apr 11, 2012 4:40 pm

Thank You



Re: Read your gmail using Java code

Fri May 11, 2012 3:38 am

Can you please post GUILogger please.....

Re: Read your gmail using Java code

Sat May 12, 2012 9:57 pm

Code:



import java
.awt.Color;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;

/**
 *
 * @author Mohamed.Sami
 */
public class GUILogger {

    private static GUILogger logger = null;
    private static StyleContext context = new StyleContext();
    private static StyledDocument document = new DefaultStyledDocument(context);
    private static javax.swing.text.Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    private static final JTextPane textArea = new JTextPane(document);
    private static final JScrollPane TextAreaScroll = new JScrollPane(textArea, 
JScrollPane
.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    private static DataOutputStream dataOutputStream;
    private static final String filePath="./errorLog.txt";
    private static final File file=new File(filePath);

    private GUILogger() {
        textArea.setSize(400, 400);
        TextAreaScroll.setSize(400, 400);
        StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
        StyleConstants.setFontSize(style, 10);
        StyleConstants.setSpaceAbove(style, 1);
        StyleConstants.setSpaceBelow(style, 1);
       
        
        if
(dataOutputStream==null){


        FileOutputStream fileOutputStream=null;
            try {
                fileOutputStream = new FileOutputStream(file, true);
                dataOutputStream = new DataOutputStream(fileOutputStream);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
            }
        
          
}
    }

    public static GUILogger getInstance() {
        if (logger == null) {
            logger = new GUILogger();
        }
        return logger;
    }
  public void clearArea() {
        try {
            document.remove(0, document.getLength());
        } catch (BadLocationException ex) {
            Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
        }
        

    
}
    public void logInfo(String info) {

        try {

            document.insertString(document.getLength(), "\n" + new Date() + ": " + info, style);

        } catch (BadLocationException ex) {
            Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void logError(String error) {
        try {
            StyleConstants.setForeground(style, Color.red);
            document.insertString(document.getLength(), "\n" + new Date() + ": " + error, style);
            StyleConstants.setForeground(style, Color.black);
        } catch (BadLocationException ex) {
            Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
        }



    }
    public void logGood(String good) {
        try {
            StyleConstants.setForeground(style, Color.GREEN.darker());
            document.insertString(document.getLength(), "\n" + new Date() + ": " + good, style);
            StyleConstants.setForeground(style, Color.black);
        } catch (BadLocationException ex) {
            Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
        }



    }
    public void logToFile(String information){
        try {
          
            dataOutputStream
.writeUTF("\n Log Date:" + new Date() + ": " + information);
            dataOutputStream.flush();
        } catch (IOException ex) {
            ex.printStackTrace();
            logError("Failed To Log To System File"+filePath+" :Error"+ex);
            Logger.getLogger(GUILogger.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static GUILogger getLogger() {
        return logger;
    }

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

    public static JScrollPane getTextAreaScroll() {
        return TextAreaScroll;
    }

    public static JTextPane getTextArea() {
        return textArea;
    }

    
}
 


Re: Read your gmail using Java code

Mon Aug 13, 2012 12:19 pm

i am getting this error


javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:130)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at com.servingxml.app.consoleapp.ReadMailPOP.readAllMessages(ReadMailPOP.java:73)
at com.servingxml.app.consoleapp.ReadMailPOP.main(ReadMailPOP.java:288)

Post a reply
  Related Posts  to : Read your gmail using Java code
 Read list of files in java I/O code     -  
 simple code to read properties in java     -  
 Read stream from URL using Java     -  
 Write and Read to File In Java Example     -  
 Read double values type from file in java     -  
 java code for chat     -  
 Algorithms code in java     -  
 GamePLay java code ( please help )     -  
 Java Insertion Sort Code     -  
 need java client/server code     -  

Topic Tags

Java Email