Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;

import javax.swing.JOptionPane;

public class Main {
    /**
     * Show input dialog with specified title and message.
     * 
     * @param parent
     *            the parent component of the input dialog, set {@code null} if
     *            not has one
     * @param title
     *            the title of the dialog
     * @param message
     *            the message to display
     * @return the input string, may be an empty string
     */
    public static String inputDialog(Component parent, String title, String message) {
        return JOptionPane.showInputDialog(parent, message, title, JOptionPane.INFORMATION_MESSAGE);
    }

    /**
     * Show input dialog with specified title, message and initial input
     * content.
     * 
     * @param parent
     *            the parent component of the input dialog, set {@code null} if
     *            not has one
     * @param title
     *            the title of the dialog
     * @param message
     *            the message to display
     * @param initial
     *            the initial input content
     * @return the input string, may be an empty string
     */
    public static String inputDialog(Component parent, String title, String message, String initial) {
        Object obj = JOptionPane.showInputDialog(parent, message, title, JOptionPane.INFORMATION_MESSAGE, null,
                null, initial);
        if (obj == null)
            return null;
        else
            return obj.toString();
    }
}