如何在Java上创建一个完美的整数对话框?

如何在Java上创建一个完美的整数对话框?,java,swing,dialog,Java,Swing,Dialog,我想在Java上创建一个完美的整数对话框,在这里您不能键入字母,只能键入数字 这是我的密码: public class PMain { public static void main(String args[]) { String a = JOptionPane.showInputDialog("Type the number for 'A'"); int A = Integer.parseInt(a.trim()); String b =

我想在Java上创建一个完美的整数对话框,在这里您不能键入字母,只能键入数字

这是我的密码:

public class PMain {
    public static void main(String args[]) {
        String a = JOptionPane.showInputDialog("Type the number for 'A'");
        int A = Integer.parseInt(a.trim());
        String b = JOptionPane.showInputDialog("Type the number for 'B'");
        int B = Integer.parseInt(b.trim());
    }
}

您可以为此创建自己的对话框(而不是JOptionPane),并使用JFormattedTextField和MaskFormatter。你可以找到一个例子。

对我来说,可能的副本听起来不太完美。我希望完美的对话框能够支持像
1e6
这样的科学记数法,花费一百万美元。:)