JNumberTextField:为什么不起作用

JNumberTextField: Why is not work

但我在 youtube 上读到了它以及如何将 JTextField 设置为 JNumberTextField 。因为我只想输入数字。如果有人按其他键,则字符不会显示在文本字段中

import javax.swing.*;
    public class example {
        public static void main(String aa[])
        {
            JNumberTextField num = JNumberTextField();
            num.setColumns(15);
            num.setFormat(JNumberTextField.DECIMAL);
            num.setPrecision(4);
            num.setAllowNegative(false);

            JFrame f = new JFrame();
            f.add(num);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(200,200);
            f.setVisible(true);
        }

    }

我正在使用 JNumberTextField,因为我只想输入数字,但它不起作用。我正在 youtube 教程上阅读它

错误是

loop.java:5: cannot find symbol
symbol  : class JNumberTextField
location: class example
        JNumberTextField num = JNumberTextField()
        ^
loop.java:5: cannot find symbol
symbol  : method JNumberTextField()
location: class example
        JNumberTextField num = JNumberTextField()
                               ^
loop.java:7: cannot find symbol
symbol  : variable JNumberTextField
location: class example
        num.setFormat(JNumberTextField.DECIMAL);

他们使用自己的习惯 class。

他们使用自己的习惯 class。 如果你只想输入数字然后使用格式化文本字段