问题之三个输入框
問題描述:
?? 等價類劃分中的EditBox問題的升級版!!!三個輸入框~
???三個輸入框,都只能允許1到6個英文字符或數(shù)字,按OK結(jié)束。
?
等價類劃分:
| 編號 | 有效等價類 | 編號 | 無效等價類 |
| 1 | 1—6(長度) | 3 | 0或>=7 |
| 2 | a-z,A-Z,0-9(字符) | 4 | 英文/數(shù)字以外字符,控制字符,標(biāo)點符號 |
?
根據(jù)有效或無效的等價類設(shè)計的測試用例:
| 編號 | 第一框 | 第二框 | 第三框 | 期待輸出 |
| 1 | ? | 123ert | .,12 | 第一框的長度應(yīng)該為1-6 第二框輸入正確 第三框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9 |
| 2 | wsed2 | Ss1w3e | SSEEjo | 第一框輸入正確 第二框輸入正確 第三框輸入正確 |
| 3 | iu,.l | ,, | 12e3r45g | 第一框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9 第二框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9 第三框的長度應(yīng)該為1-6 |
| 4 | ? | ji7ug6t | \=8@ | 第一框的長度應(yīng)該為1-6 第二框的長度應(yīng)該為1-6 第三框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9 |
| 5 | FR45^ | AwS666 | ? | 第一框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9 第二框輸入正確 第三框的長度應(yīng)該為1-6 |
?
?
源代碼如下:
?
1 package test; 2 3 import javafx.application.Application; 4 import javafx.event.ActionEvent; 5 import javafx.event.EventHandler; 6 import javafx.scene.Scene; 7 import javafx.scene.control.Button; 8 import javafx.scene.control.TextField; 9 import javafx.scene.layout.AnchorPane; 10 import javafx.scene.layout.StackPane; 11 import javafx.scene.text.Text; 12 import javafx.stage.Stage; 13 14 public class test extends Application{ 15 public static void main(String[ ] args) { 16 test.launch( args ); 17 } 18 19 public void start( Stage primaryStage ) { 20 primaryStage.setTitle( "Test!" ); 21 AnchorPane root = new AnchorPane(); 22 23 Text text = new Text("請輸入1到6位 數(shù)字或字母"); 24 Text text1 = new Text("第一框:"); 25 Text text2 = new Text("第二框:"); 26 Text text3 = new Text("第三框:"); 27 final TextField name1 = new TextField(); 28 final TextField name2 = new TextField(); 29 final TextField name3 = new TextField(); 30 31 AnchorPane.setLeftAnchor(text,50.0); 32 AnchorPane.setTopAnchor(text, 50.0); 33 AnchorPane.setLeftAnchor(text1,50.0); 34 AnchorPane.setTopAnchor(text1, 100.0); 35 AnchorPane.setLeftAnchor(text2,50.0); 36 AnchorPane.setTopAnchor(text2, 150.0); 37 AnchorPane.setLeftAnchor(text3,50.0); 38 AnchorPane.setTopAnchor(text3, 200.0); 39 AnchorPane.setLeftAnchor(name1,150.0); 40 AnchorPane.setTopAnchor(name1, 100.0); 41 AnchorPane.setLeftAnchor(name2,150.0); 42 AnchorPane.setTopAnchor(name2, 150.0); 43 AnchorPane.setLeftAnchor(name3,150.0); 44 AnchorPane.setTopAnchor(name3, 200.0); 45 46 Button button = new Button("OK"); 47 AnchorPane.setLeftAnchor(button,200.0); 48 AnchorPane.setTopAnchor(button, 250.0); 49 50 button.setOnAction(new EventHandler<ActionEvent>(){ 51 public void handle(ActionEvent arg0){ 52 String one = name1.getText(); 53 String two = name2.getText(); 54 String three = name3.getText(); 55 AnchorPane root1 = new AnchorPane(); 56 Stage stage1 = new Stage(); 57 Text text0 = new Text(); 58 Text text5 = new Text(); 59 Text text6 = new Text(); 60 AnchorPane.setLeftAnchor(text0, 50.0); 61 AnchorPane.setTopAnchor(text0, 50.0); 62 AnchorPane.setLeftAnchor(text5, 50.0); 63 AnchorPane.setTopAnchor(text5, 100.0); 64 AnchorPane.setLeftAnchor(text6, 50.0); 65 AnchorPane.setTopAnchor(text6, 150.0); 66 root1.getChildren().addAll(text0,text5,text6); 67 68 if(one.length()<7 && one.length()>0 69 && one.matches("([a-z]|[A-Z]|[0-9]){1,}")) 70 text0.setText("第一框輸入正確"); 71 else if(one.length()<1 || one.length()>6) 72 text0.setText("第一框的長度應(yīng)該為1-6"); 73 else 74 text0.setText("第一框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9"); 75 76 if(two.length()<7 && two.length()>0 77 && two.matches("([a-z]|[A-Z]|[0-9]){1,}")) 78 text5.setText("第二框輸入正確"); 79 else if(two.length()<1 || two.length()>6) 80 text5.setText("第二框的長度應(yīng)該為1-6"); 81 else 82 text5.setText("第二框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9"); 83 84 if(three.length()<7 && three.length()>0 85 && three.matches("([a-z]|[A-Z]|[0-9]){1,}")) 86 text6.setText("第三框輸入正確"); 87 else if(three.length()<1 || three.length()>6) 88 text6.setText("第三框的長度應(yīng)該為1-6"); 89 else 90 text6.setText("第三框的字符應(yīng)當(dāng)僅包含a-z,A-Z,0-9"); 91 92 Scene scene2 = new Scene (root1,300,200); 93 stage1.setScene(scene2); 94 stage1.show(); 95 96 97 } 98 }); 99 100 root.getChildren().addAll(button,text,text1,text2,text3,name1,name2,name3); 101 102 primaryStage.setScene(new Scene(root, 500, 500)); 103 primaryStage.show( ); 104 } 105 106 }?
運行結(jié)果截圖:
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/erchen/p/4393243.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
- 上一篇: 动态规划专题 01背包问题详解【转】
- 下一篇: libsvm学习(二)——第一次体验li