1

Swing work 値として int 変数を持つテキスト フィールドの単純な検証を行うのが困難です。次のものが必要です。

  • 数字のみを許可する
  • 0 以下の値を許可しない
  • 記入は必須です。
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) 

{                                         
        // TODO add your handling code here:

   User controller=new User(

   new Integer(textuid.getText().trim()),textname.getText(),
   textpassword.getText(),textrepassword.getText());
   controller.saveUser(db.getCon());

   // int a= new Integer(textuid.getText().trim());
   System.out.print(controller.getUid());

   if(Integer.parseInt(textuid.getText()) <=0){
      JOptionPane.showMessageDialog( textuid, "Must enter a value greater than zero"); }
   if(textuid.getText().equals("s")){
           JOptionPane.showMessageDialog( textuid, "Must enter a value greater than zero"); }
//        if(textname.getText().equals(""))
//            {
//           JOptionPane.showMessageDialog( textname, "Name not empty"); 
//        }
//           if(textpassword.getText().equals("")){
//           JOptionPane.showMessageDialog( textname, "Password not empty"); 
//        }
//           if(textrepassword.getText().equals("")){
//           JOptionPane.showMessageDialog( textname, "Password not empty"); 
//        }
    }          

エラーメッセージを表示

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.<init>(Integer.java:660)
at com.smart.ui.UserForm.btnsaveActionPerformed(UserForm.java:149)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

私はこれを解決することはできません。助けてください。それは私の最初の投稿です

4

0 に答える 0