JOptionPanehelps to easily eject standard dialogs that require the user to provide a value or notify them. But sometimes look at the API is also particularly annoying, because many methods, parameters, especially difficult to remember. Here I give a few common methods for your reference.
(1) public static int showconfirmdialog(Component parentcomponent, Object message); This method is to bring up the option Yes, The No and Cancel dialog box, titled Select an Option. First of all to understand the general meaning, here we mainly focus on Showconfirmdialog.
For example, if I don't want three options, I can use Joptionpane.showconfirmdialog (null, "No more questions, do you want to quit?") "," Prompt Box ", 2); Implementation, the first parameter means
---> Determine where the dialog box is displayed, Frame or if it is null parentComponent not Frame , use the defaultFrame;第二个参数是显示在弹出框中的内容,及按钮上方的内容;第三个参数是对话框的标题,相当于JFrame.setTitle("字符");设置后显示的内容;第四个参数是选项个数,这里的2表示只有是和否两个选项。
(2) public static void Showinternalmessagedialog(Component parentcomponent,object message) This method is to bring up the Internal confirmation dialog box panel. The dialog box is an informational message dialog box titled "Message". This is a pop-up dialog that can be entered, you can enter the appropriate location of the content you want to enter, this method is nothing special, there is no more to say.
(3) public static void Showmessagedialog(Component parentcomponent,object message); This method is to bring up the title "message" Information message dialog box. This is a prompt dialog box with only a "OK" option.
Of course, here is just a simple introduction, the above three methods of overloading methods There are many, you can find the API.
Basic ways to use Joptionpane in Java