Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Main {
    protected static String messagerHeader = "Database Manager Swing Error";
    protected static String Native = "Native";
    protected static String Java = "Java";
    protected static String Motif = "Motif";

    static void setSwingLAF(java.awt.Component comp, String targetTheme) {

        try {
            if (targetTheme.equalsIgnoreCase(Native)) {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } else if (targetTheme.equalsIgnoreCase(Java)) {
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            } else if (targetTheme.equalsIgnoreCase(Motif)) {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
            }

            //            if (targetTheme.equalsIgnoreCase(plaf)){
            //                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            //            }
            //
            //            if (targetTheme.equalsIgnoreCase(GTK)){
            //                UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
            //            }
            SwingUtilities.updateComponentTreeUI(comp);

            if (comp instanceof java.awt.Frame) {
                ((java.awt.Frame) comp).pack();
            }
        } catch (Exception e) {
            errorMessage(e);
        }
    }

    protected static void errorMessage(String errorMessage) {

        /**
         * Display Jpanel Error messages any text Errors. Overloads
         * errorMessage(Exception exceptionMsg)
         */
        Object[] options = { "OK" };

        JOptionPane.showOptionDialog(null, errorMessage, messagerHeader, JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[0]);

        // DatabaseManagerSwing.StatusMessage(READY_STATUS);
    }

    public static void errorMessage(Exception exceptionMsg) {
        errorMessage(exceptionMsg, false);
    }

    public static void errorMessage(Exception exceptionMsg, boolean quiet) {

        /**
         * Display Jpanel Error messages any SQL Errors. Overloads
         * errorMessage(String e)
         */
        Object[] options = { "OK", };

        JOptionPane.showOptionDialog(null, exceptionMsg, messagerHeader, JOptionPane.DEFAULT_OPTION,
                JOptionPane.ERROR_MESSAGE, null, options, options[0]);

        if (!quiet) {
            exceptionMsg.printStackTrace();
        }

        // DatabaseManagerSwing.StatusMessage(READY_STATUS);
    }
}