问题描述
大家好,想在JtextfieldfocusLost检测填写是否正确,可在提示了出错信息后,本来想返回这个jtextfield,不知道为何这个focuslost却被叫了很多次。privatevoidjTextField1FocusLost(java.awt.event.FocusEventevt){//TODOaddyourhandlingcodehere:evt.getSource();JTextFieldroomTag=(JTextField)evt.getSource();Stringtext=roomTag.getText();if(text.length()>=3){try{Integer.parseInt(text);}catch(NumberFormatExceptionnfe){Toolkit.getDefaultToolkit().beep();SwingUtilities.invokeLater(newFocusGrabber(this.jTextField1));JOptionPane.showMessageDialog(null,"Itmustbeanumericvalue");//roomTag.requestFocus();//jTextField1.requestFocus();//return;}}else{JOptionPane.showMessageDialog(null,"Itmustbe3charsatleast");//roomTag.requestFocus();//jTextField1.requestFocus();//return;}}
解决方案
解决方案二:
没人知道答案吗
时间: 2024-09-28 01:00:39