The Joptionpane class has 4 static methods for displaying dialog boxes :
Message, options, Confirmation, Input dialog box
showMessageDialog://显示一条消息并等待用户OKshowConfirmDialog://显示一条消息并等待用户确认//显示一条消息并获得一组选项的选择showInputDialog: //显示一条消息并获得输入的一行文本
The message dialog box has the following methods:
Parentcomponet//Parent ComponentMassage//Message Object displayed in dialog box (string, icon, component or array)Title//dialog box titleMessageType//message type, decision icon, value: Error_message,information_message,warning_message,question_message,plain_message oneIcon//icon to replace the standard iconImport Javax.swing.JOptionPane; Public classMessage { Public Static void Main(string[] args) {Joptionpane.showmessagedialog (NULL,"This is message!","Messagedialog", joptionpane.question_message);//joptionpane.showmessagedialog (NULL, "This is message!", "Messagedialog", joptionpane.information_message);}}//Message type decision icon
The Options dialog box has the following methods:
//参数parentComponet //父组件massage //显示在对话框中的消息对象(字符串String,图标Icon,组件或者数组)title //对话框标题messageType //消息类型,决定图标,取值:ERROR_MESSAGE,INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE,PLAIN_MESSAGE之一optionType //取值DEFAULT_OPTION,YES_NO_OPTION,YES_NO_CANCEL_OPTION,OK_CANCEL_OPTIONicon //用于替代标准图标的图标otptions // 一组选项,可以是字符串,图标,组件
OK dialog box:
//ParametersParentcomponet//Parent ComponentMassage//Message Object displayed in dialog box (string, icon, component or array)Title//dialog box titleMessageType//message type, decision icon, value: Error_message,information_message,warning_message,question_message,plain_message oneOptiontype//value default_option,yes_no_option,yes_no_cancel_option,ok_cancel_optionIcon//icon to replace the standard iconImport Javax.swing.JOptionPane; Public classMessage { Public Static void Main(string[] args) {Joptionpane.showconfirmdialog (NULL,"This a warning!","warningdialog!", Joptionpane.yes_no_option, Joptionpane.warning_message);//joptionpane.showconfirmdialog (NULL, "This a warning!", "warningdialog!", Joptionpane.yes_no_cancel_option, Joptionpane.warning_message);}}//optiontype The number of different buttons is different
Enter the dialog box:
//ParametersParentcomponet//Parent ComponentMassage//Message Object displayed in dialog box (string, icon, component or array)Title//dialog box titleMessageType//message type, decision icon, value: Error_message,information_message,warning_message,question_message,plain_message oneIcon//icon to replace the standard icondefault //default values presented to the user Public classMessage { Public Static void Main(string[] args) {String str= Joptionpane.showinputdialog (NULL,"Enter an integer","Input dialog box", joptionpane.plain_message);//Returns a string}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
4 common dialog boxes for Joptionpane