Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在启动程序时将光标聚焦在JTextField上?_Java_Jtextfield_Startup_Joptionpane - Fatal编程技术网

Java 如何在启动程序时将光标聚焦在JTextField上?

Java 如何在启动程序时将光标聚焦在JTextField上?,java,jtextfield,startup,joptionpane,Java,Jtextfield,Startup,Joptionpane,我想知道是否有人能把我引向正确的方向?我希望在启动程序时将光标聚焦在JTextField上?非常感谢您的帮助,我在这方面已经坚持了一段时间了! p、 使用来自不同类的switch语句控制菜单 public int menuMain() { int option = 0; String opt1 = new String("1. Account Settings :"); String opt2 = new String("2. Buy a quick pick :")

我想知道是否有人能把我引向正确的方向?我希望在启动程序时将光标聚焦在JTextField上?非常感谢您的帮助,我在这方面已经坚持了一段时间了! p、 使用来自不同类的switch语句控制菜单

public int menuMain() {

    int option = 0;

    String opt1 = new String("1. Account Settings :");
    String opt2 = new String("2. Buy a quick pick :");
    String opt3 = new String("3. Buy a ticket using own numbers  :");
    String opt4 = new String("4. Start the draw :");
    String opt5 = new String("5. Display previous draw results :");
    String opt6 = new String("6. Exit\n");
    String opt7 = new String("\n");
    String msg = new String("Enter Option:");
    JTextField opt = new JTextField("");

    Object message[] = new Object[10];
    message[0] = myIcon;
    message[1] = opt1;
    message[2] = opt2;
    message[3] = opt3;
    message[4] = opt4;
    message[5] = opt5;
    message[6] = opt6;
    message[7] = opt7;
    message[8] = msg;
    message[9] = opt;

    int response = JOptionPane.showConfirmDialog(null, message,
            "DVD Data Entry", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, anIcon);

    if (response == JOptionPane.CANCEL_OPTION) {
        System.exit(0);
    }

    else {
        try {

            option = Integer.parseInt(opt.getText());

            optionLimitations(option, 1, 6);

        }

        catch (InputBoundariesException a) {
            JOptionPane.showMessageDialog(null, a.getMessage()
                    + "Please Try Again.", "Input Error",
                    JOptionPane.ERROR_MESSAGE);
        }

        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Input must be a number. "
                    + "Please Try Again.", "Input Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    return option;

}
这个问题有用吗?不,它只是默认为“OK”按钮,但我感谢您的回复。