軟體測試——字串檢測2.0

來源:互聯網
上載者:User

標籤:

  1 import javafx.application.Application;  2 import javafx.event.ActionEvent;  3 import javafx.event.EventHandler;  4 import javafx.scene.Scene;  5 import javafx.scene.control.Button;  6 import javafx.scene.control.TextField;  7 import javafx.scene.layout.AnchorPane;  8 import javafx.scene.layout.HBox;  9 import javafx.scene.text.Text; 10 import javafx.stage.Stage; 11  12 public class Test extends Application{ 13     public static void main(String[] args) { 14         Test.launch(args); 15     }  16        17     public void start(Stage stage ){ 18         stage.setTitle("UserForm1");           19         AnchorPane root = new AnchorPane(); 20         21         //The first one box; 22         HBox hbox1 = new HBox(8); 23         Text t1 = new Text("Name One: "); 24         final TextField tf1 = new TextField(); 25         Button btn1 = new Button("Enter"); 26         hbox1.getChildren().addAll(t1, tf1, btn1); 27           28         btn1.setOnAction(new EventHandler<ActionEvent>(){ 29             @Override 30             public void handle(ActionEvent actEvt) { 31                 if(check(tf1.getText().toString())) 32                     System.out.println("Name One is true"); 33                     else 34                     System.out.println("Name One is false"); 35                 } 36         }); 37          38         AnchorPane.setTopAnchor(hbox1, 30.0); 39         AnchorPane.setLeftAnchor(hbox1, 30.0); 40         root.getChildren().add(hbox1); 41          42         //The second one  43         HBox hbox2 = new HBox(8); 44         Text t2 = new Text("Name Two: "); 45         final TextField tf2 = new TextField(); 46         Button btn2 = new Button("Enter"); 47         hbox2.getChildren().addAll(t2, tf2, btn2); 48           49         btn2.setOnAction(new EventHandler<ActionEvent>(){ 50             @Override 51             public void handle(ActionEvent actEvt) { 52                 if(check(tf2.getText().toString())) 53                     System.out.println("Name Two is true"); 54                     else 55                     System.out.println("Name Two is false"); 56                 } 57         }); 58          59         AnchorPane.setTopAnchor(hbox2, 90.0); 60         AnchorPane.setLeftAnchor(hbox2, 30.0); 61         root.getChildren().add(hbox2); 62          63         //The third one  64         HBox hbox3 = new HBox(8); 65         Text t3 = new Text("Name Three: "); 66         final TextField tf3 = new TextField(); 67         Button btn3 = new Button("Enter"); 68         hbox3.getChildren().addAll(t3, tf3, btn3); 69           70         btn3.setOnAction(new EventHandler<ActionEvent>(){ 71             @Override 72             public void handle(ActionEvent actEvt) { 73                 if(check(tf3.getText().toString())) 74                     System.out.println("Name Three is true"); 75                     else 76                     System.out.println("Name Three is false"); 77                 } 78         }); 79          80         AnchorPane.setTopAnchor(hbox3, 150.0); 81         AnchorPane.setLeftAnchor(hbox3, 30.0); 82         root.getChildren().add(hbox3); 83          84         stage.setScene(new Scene(root, 400, 200)); 85         stage.show();  86     } 87       88     public boolean check(String s){ 89         char array[] = new char[s.length()]; 90         array = s.toCharArray(); 91         if (s.length() < 1 || s.length() > 6) 92             return false;           93         if (s.length() != 0){ 94             for (int i = 0; i < s.length(); i++){ 95                 if(!Character.isDigit(array[i]) && !Character.isAlphabetic(array[i])) 96                     return false; 97             } 98         } 99            return true;100     }101 }

 

軟體測試——字串檢測2.0

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.