Java s、 其中null表示用户可以输入他们想要的任何内容,通常通过JTextField。initialSelectionValue是提示用户使用的初始值。由UI决定如何最好地表示SelectionValue,但通常会使用JComboBox、JList或JTextField

Java s、 其中null表示用户可以输入他们想要的任何内容,通常通过JTextField。initialSelectionValue是提示用户使用的初始值。由UI决定如何最好地表示SelectionValue,但通常会使用JComboBox、JList或JTextField,java,swing,joptionpane,Java,Swing,Joptionpane,参数: 父组件-对话框的父组件 消息-要显示的对象 标题-要在对话框标题栏中显示的字符串 消息类型-要显示的消息类型:错误消息、信息消息、警告消息、问题消息或普通消息 图标-要显示的图标图像 selectionValues-提供可能选择的对象数组 initialSelectionValue-用于初始化输入字段的值 返回: 用户的输入,或null表示用户取消了输入 抛出: HeadlessException-如果GraphicsEnvironment.ishadless返回true是否收到警告或任

参数:

父组件-对话框的父组件

消息-要显示的对象

标题-要在对话框标题栏中显示的字符串

消息类型-要显示的消息类型:错误消息、信息消息、警告消息、问题消息或普通消息

图标-要显示的图标图像

selectionValues-提供可能选择的对象数组

initialSelectionValue-用于初始化输入字段的值

返回:

用户的输入,或null表示用户取消了输入

抛出:


HeadlessException-如果GraphicsEnvironment.ishadless返回true

是否收到警告或任何错误?如果是错误,那是什么?@10sw33评论flagged@10sw33每个人警告是一个很好的指示器,表明您的期望和编译器发生冲突,并且可能表明API发生了更改,并且它正在工作。您是否收到警告或任何错误?如果是错误,那是什么?@10sw33评论flagged@10sw33每个人警告是一个很好的指示器,表明您的期望和编译器发生冲突,并且可能表明API发生了更改,并且它正在工作。您是否收到警告或任何错误?如果是错误,那是什么?@10sw33评论flagged@10sw33每个人警告是一个很好的指示器,表明您的期望和编译器发生冲突,并且可能表明API发生了更改,并且它正在工作。您是否收到警告或任何错误?如果是错误,那是什么?@10sw33评论flagged@10sw33每个人警告是一个很好的指示器,表明您的期望和编译器发生冲突,并且可能表明API发生了更改,并且它正在工作
String[] trollDo= {"Try and sneak the horses away.",
                   "Go back and tell the others.", 
                   "Kill the trolls."};
String trollChoice =(String) JOptionPane.showInputDialog(null,
           "What will "+playerName+" do?",null,JOptionPane.QUESTION_MESSAGE,
           trollDo,trollDo[0]);
error: no suitable method found for showInputDialog(<null>,String,<null>,int,String[],String)
    String trollChoice = (String) JOptionPane.showInputDialog(
                                             ^
    method JOptionPane.showInputDialog(Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showInputDialog(Object,Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showInputDialog(Component,Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showInputDialog(Component,Object,Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showInputDialog(Component,Object,String,int) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showInputDialog(Component,Object,String,int,Icon,Object[],Object) is not applicable
      (actual and formal argument lists differ in length)
1 error
String trollChoice = (String) JOptionPane.showInputDialog(
                null,
                "What will " + playerName + " do?", 
                null,
                JOptionPane.QUESTION_MESSAGE,
                null, // This one here
                trollDo, 
                trollDo[0]);
 JOptionPane.showInputDialog(null, e, playerName, messageType, null, trollDo, playerName);