/*
JOptionPane illustration.
Aditya Mathur.
March 24, 2019
 */
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Font;

public class OptionPaneExamples {
    public static void main(String[] args) {
        final int w=600, h=400;
        final Dimension d=new Dimension(w,h);
        final Font f=new Font("Arial", Font.BOLD, 24);
        // Set up window size and fonts
        UIManager.put("OptionPane.minimumSize", d);
        UIManager.put("OptionPane.messageFont", f);
        // Create object.
        OptionPaneExamples opx = new OptionPaneExamples();
        // Display various panes.
        opx.errorMessage(); //  Display error message
        opx.simpleMessage(); // Display simple message
        opx.confirmMessage(); // Ask for confirmation
        opx.inputMessage(); // Get input
        System.exit(0); // Exit
    }// End of main

    public void errorMessage() {
        // Error message
        String msg = "Invalid input; must be greater than 0";
        int msgType = JOptionPane.ERROR_MESSAGE;
        String title = "Error report";
        JOptionPane.showMessageDialog(null,
                msg, title, msgType);
    }// End of errorMessage

    public void simpleMessage() {
        // Simple  message
        ImageIcon img = new ImageIcon("rose.jpg");
        Object[] text = {"I love roses,", "Habiscus,",
                "Marigold,", "and.."};
        int msgType = JOptionPane.INFORMATION_MESSAGE;
        String title = "Love for flowers";
        JOptionPane.showMessageDialog(null,
                text, title, msgType, img);
    }// End of simpleMessage

    public void confirmMessage() {
        // Confirm message
        Object[] options = {"Yep", "No"};
        int optType = JOptionPane.YES_NO_OPTION;
        String title = "Confirm";
        String msg = "Is it over?";
        int msgType = JOptionPane.QUESTION_MESSAGE;
        int yesNo=JOptionPane.showOptionDialog(null, msg,
                title, optType, msgType, null, options, options[0]);
        System.out.println(yesNo);
    }// End of confirmMessage

    public void inputMessage() {
        // Input message
        String title = "Do you trust me?";
        String msg = "Enter your password";
        int msgType = JOptionPane.PLAIN_MESSAGE;
        String p = (String) JOptionPane.showInputDialog(null, msg,
                title, msgType);
        System.out.println("Never give away your password: " + p);
    }// End of input Message
}// End of class


