分享

求java中joptionpane 的用法?

 horse_home 2014-06-04
你可以查java api,JOptionPane是无法实现将两次输入放入一个对话框里的,所有showInputDialog的构造方法如下:
public static String showInputDialog(Object message) throws HeadlessException
显示请求用户输入的问题消息对话框。该对话框使用默认的边框,通常意味着在屏幕上居中显示。

public static String showInputDialog(Object message, Object initialSelectionValue)
显示请求用户输入的问题消息对话框,它带有已初始化为 initialSelectionValue 的输入值。该对话框使用默认的窗体,通常意味着在屏幕上居中显示。

public static String showInputDialog(Component parentComponent, Object message)throws HeadlessException
显示请求用户输入内容的问题消息对话框,它以 parentComponent 为父级。该对话框显示于 Component 的窗体的上部,通常位于 Component 之下。

public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)显示请求用户输入内容的问题消息对话框,它以 parentComponent 为父级。输入值将被初始化为 initialSelectionValue。该对话框显示于 Component 的窗体的上部,通常位于 Component 之下。

public static String showInputDialog(Component parentComponent,Object message,String title,int messageType)throws HeadlessException
显示请求用户输入内容的对话框,它以 parentComponent 为父级,该对话框的标题为 title,消息类型为 messageType。

public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException
提示用户在可以指定初始选择、可能选择及其他所有选项的模块化的对话框中输入内容。用户可以从 selectionValues 中进行选择,其中 null 表示用户可以输入想输入的任何内容,通常依靠 JTextField 来实现。initialSelectionValue 是用于提示用户的初始值。由 UI 决定如何最好的表示 selectionValues,但通常情况下将使用 JComboBox、JList 或 JTextField。

如果要达到两次输入在一个对话框的效果,可以尝试用JInternalFrame。

如果要用JOptionPane获得用户输入,同样可以查api查到方法,如下:
getInputValue()   如果 wantsInput 为 true,则返回用户已输入的值。
getSelectionValues()   返回输入选择值
getValue()   返回用户所选值

查api~~

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约