How to Show the Option Dialog in Java


In this example, we can get the method to show the option dialog in Java.

Source Code

package com.beginner.examples;

import javax.swing.JOptionPane;

public class OptionDialogExample {

    public static void main(String[] args){
    	String[] options = {"I'm good.","I'm fine.","No.I don't feel good."};
        int n = JOptionPane.showOptionDialog(null, "Are you ok?",
                "Click a button",JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        //System.out.println(n);
        System.out.println("Done!");
    }
}

Output:

Done!

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments