用户输入以显示在下拉菜单中

时间:2019-05-13 19:36:26

标签: java swing

我正在尝试创建一个对话框,要求用户输入并在下拉菜单选项中显示相同的输入。现在,需要在代码中设置输入。

class Main {
    static JFrame frame = new JFrame();
    public static void main (String [] args) throws
    InterruptedException{
    JDialog.setDefaultLookAndFeelDecorated(true);
    Object[] selectionValues = { "Cat", "Dog", "Rate" };
    String initialSelection = "Cat";
    Object selection = JOptionPane.showInputDialog(null, 
        "Which player are you?", 
        "Welcome to Crappy birds!!", 
        JOptionPane.QUESTION_MESSAGE, null, selectionValues, 
        initialSelection);
    System.out.println(selection);
}

0 个答案:

没有答案