简体   繁体   English

如何使用 netbeans 在 java 上验证从 jlabel 到 jtextfield 的值

[英]How to validate value from jlabel to jtextfield on java using netbeans

I have an auto generated numbers that i want the user to input in order to have access to the full function of the program, if the value from the label is the same with the value entered into the textbox, the functions should be enabeled else it should prompt out a JOptionPane that the value entered is not valid, if the value are input *3 it should exit the program.我有一个自动生成的数字,我希望用户输入以访问程序的完整 function,如果 label 中的值与输入到文本框中的值相同,则应启用功能,否则应该提示输入的值无效的 JOptionPane,如果输入的值 *3 它应该退出程序。

Swing offers an InputVerifier for input verification. Swing 提供InputVerifier用于输入验证。 You could implement one and add it the JTextField .您可以实现一个并将其添加到JTextField See InputVerifier docs .请参阅InputVerifier 文档 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 , you could also validate user input within KeyEvents .如果这不是您想要的,请查看KeyListener ,您还可以在KeyEvents中验证用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM