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

时间:2014-09-24 22:06:01

标签: java jtextfield startup joptionpane

我想知道是否有人能引导我朝着正确的方向前进?我希望在启动程序时将光标集中在JTextField上?非常感谢任何帮助,我已经坚持了一段时间! 附:使用来自不同类的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;

}

0 个答案:

没有答案