Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Carrot2 project.
 *
 * Copyright (C) 2002-2006, Dawid Weiss, Stanislaw Osinski.
 * Portions (C) Contributors listed in "carrot2.CONTRIBUTORS" file.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

import java.awt.*;

import javax.swing.*;

public class Main {
    /**
     * Displays a message dialog with given information.
     */
    public static void showInformationDialog(Component component, String message) {
        final JPanel panel = new JPanel(new BorderLayout(5, 5));

        final JLabel messageLabel = new JLabel(message);
        messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize()));

        panel.add(messageLabel, BorderLayout.CENTER);

        // Adjust stack trace dimensions
        final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
        screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7);
        final Dimension maxStackTraceDimension = new Dimension(500, 500);
        maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()),
                Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight()));

        JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE);
    }
}