關於3個EditBox的測試以及相應的java程式

來源:互聯網
上載者:User

標籤:

有關問題:

有3個EditBox,每次允許輸入1~6個英文字元或數字,按enter結束

關注點:

輸入字元的長度,輸入字元的類型

等價類別劃分:

編號 有效or無效 等價類別內容
1 有效 長度為1-6
2 有效 內容為英文字元或數字
3 有效 3個EditBox都正確
4 無效 長度為0或大於6
5 無效 內容不全為英文字元和數字
6 無效 3個EditBox不全都正確

 

測試案例:

輸入1 輸入2 輸入3 覆蓋等價類別 預測輸出
123 abc AS1acx 123 ok
123 abc   426 false
123 abc, AS1acx 156 false
1234567 abc. AS1acx 456 false

 

測試結果:

                                                              

代碼:

 1 import javafx.application.Application; 2 import javafx.event.ActionEvent; 3 import javafx.event.EventHandler; 4 import javafx.scene.*; 5 import javafx.scene.control.Button; 6 import javafx.scene.control.TextField; 7 import javafx.scene.layout.AnchorPane; 8 import javafx.scene.layout.StackPane; 9 import javafx.scene.text.Text;10 import javafx.stage.Stage;11 12  class Kuang extends AnchorPane{13      Text text = new Text("Name:");14      TextField textField=new TextField();15      double hight = 0;16     Kuang(double hight,AnchorPane pane){17         this.getChildren().addAll(text,textField);18         this.hight = hight;19         AnchorPane.setTopAnchor(this, hight);20         AnchorPane.setLeftAnchor(this, 50.0);21         pane.getChildren().add(this);22     }23     public boolean check(){24         int length = this.textField.getText().length();25         if(length > 6 || length < 1)26             return false;27         for (char a : this.textField.getText().toCharArray()){28             if(!Character.isAlphabetic(a)&&!Character.isDigit(a))29                 return false;30         }31         return true;32     }33 }34 public class MyTest extends Application {35 36     /**37      * @param args38      */39     public static void main(String[] args) {40         // TODO Auto-generated method stub41         MyTest.launch(args);42 43     }44 45     @Override46     public void start(Stage stage) throws Exception {47         // TODO Auto-generated method stub48         stage.setTitle("MyTest");49         AnchorPane root = new AnchorPane();50         final Kuang kuang1= new Kuang(50,root);51         final Kuang kuang2= new Kuang(100,root);52         final Kuang kuang3 = new Kuang(150,root);53         Button but = new Button("enter");54         but.setOnAction(new EventHandler<ActionEvent>(){55             public void handle(ActionEvent  event){56                 String back = "false";57                 if(kuang1.check()&&kuang2.check()&kuang3.check()){58                     back = "ok";59                 }60                 System.out.println(back);61                 }62         });63         AnchorPane.setTopAnchor(but, 200.0);64         AnchorPane.setLeftAnchor(but, 100.0);65         root.getChildren().add(but);66         stage.setScene(new Scene(root,250,250));67         stage.show();68     }69 70 }

 

關於3個EditBox的測試以及相應的java程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.