如何使用 netbeans 在 java 上验证从 jlabel 到 jtextfield 的值
How to validate value from jlabel to jtextfield on java using netbeans
我有一个自动生成的数字,我希望用户输入该数字以访问程序的全部功能,如果标签中的值与输入到文本框中的值相同,则函数应该启用否则它应该提示一个 JOptionPane 输入的值无效,如果输入值 *3 它应该退出程序。
Swing 提供了一个 InputVerifier
用于输入验证。您可以实现一个并将其添加到 JTextField
。请参阅 InputVerifier docs. The textfield will get verified, as soon as another component requests the focus. You could enable/disable your components of choice in this verification-process. If this is not what you want, have a look at the KeyListener,您还可以在 KeyEvents
.
中验证用户输入
我有一个自动生成的数字,我希望用户输入该数字以访问程序的全部功能,如果标签中的值与输入到文本框中的值相同,则函数应该启用否则它应该提示一个 JOptionPane 输入的值无效,如果输入值 *3 它应该退出程序。
Swing 提供了一个 InputVerifier
用于输入验证。您可以实现一个并将其添加到 JTextField
。请参阅 InputVerifier docs. The textfield will get verified, as soon as another component requests the focus. You could enable/disable your components of choice in this verification-process. If this is not what you want, have a look at the KeyListener,您还可以在 KeyEvents
.