Java JOptionPane Error popupError(String s, Throwable e)

Here you can find the source of popupError(String s, Throwable e)

Description

popup Error

License

Open Source License

Declaration

static void popupError(String s, Throwable e) 

Method Source Code


//package com.java2s;
/*//from   w ww . j  a v a2 s . co m
Copyright (c) 2016 Steven Phillips, Miro Dudik and Rob Schapire
    
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions: 
    
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software. 
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*/

import java.io.*;
import javax.swing.*;

public class Main {
    public static boolean verbose = false, visible = true;
    static JFrame topLevelFrame = null;
    static PrintStream logOut = null;
    static long startTime, lastReportedTime;

    static void popupError(String s, Throwable e) {
        System.err.println("Error: " + s);
        String msg = logError(s, e);
        if (visible)
            JOptionPane.showMessageDialog(topLevelFrame, msg, "Error", JOptionPane.ERROR_MESSAGE);
    }

    static String logError(String s, Throwable e) {
        String msg = s + (e == null ? "" : ": " + e.toString());
        echoln(msg);
        if (e != null) {
            if (verbose)
                e.printStackTrace(System.out);
            if (logOut != null) {
                e.printStackTrace(logOut);
                logOut.flush();
            }
        } else if (logOut != null)
            new Exception().printStackTrace(logOut);
        return msg;
    }

    static void echoln() {
        echoln("");
    }

    static void echoln(String s) {
        if (logOut != null) {
            long time = System.currentTimeMillis();
            if (time > lastReportedTime + 1000) {
                logOut.println("Time since start: " + (time - startTime) / 1000.0);
                lastReportedTime = time;
            }
            logOut.println(s);
            logOut.flush();
        }
    }
}

Related

  1. errorMessage(Exception exceptionMsg, boolean quiet)
  2. exibeMsgErro(String msg)
  3. getIconError()
  4. guiError(String errormsg, String errortitle)
  5. logErrorMessage(String msg)
  6. printErrorMessageAndExit(String message)
  7. showAudioNotAvailableError(String macId)
  8. showBlockedErrorMsg(final Container parent, final String message, final boolean exit)
  9. showError(Component component, String title, String message)