简体   繁体   中英

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.

Swing offers an InputVerifier for input verification. You could implement one and add it the JTextField . See 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 , you could also validate user input within KeyEvents .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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