Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JOptionPane;

public class Main {
    /**
     * Displays a {@link JOptionPane} as a Confirm Dialog with OK and CANCEL buttons.
     * 
     * @param title The title of the Dialog.
     * @param message The message of the Dialog.
     * @return "ok" or "cancel" if clicked on the respective buttons.
     */
    public static String showConfirmationDialogWithOkCancelButtons(String title, String message) {
        int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.OK_OPTION)
            return "ok";
        if (result == JOptionPane.CANCEL_OPTION)
            return "cancel";
        return null;
    }
}