Editbox问题的实现以及Junit测试框架的简要说明

发表于:2015-6-15 11:24

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:一班&张凯悦    来源:51Testing软件测试网采编

  一、这周的EditBox由一个框改为三个框,同时进行测试,下面给出程序及截图
1 import java.util.regex.Matcher;
2 import java.util.regex.Pattern;
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.paint.Color;
11 import javafx.scene.text.Font;
12 import javafx.scene.text.Text;
13 import javafx.stage.Stage;
14
15 public class Test1 extends Application {
16     public static boolean isRegularRptCode(String rptCode,String regEx) {
17         Pattern p1 = Pattern.compile(regEx);
18         Matcher m1 = p1.matcher(rptCode);
19         boolean rs1 = m1.matches();
20         return rs1;
21     }
22     public static void main(String[] args) {
23         Test1.launch(args);
24     }
25     public void start(Stage stage)throws Exception {
26         stage.setTitle("UserForm1");
27         AnchorPane root = new AnchorPane();
28         Scene scene = new Scene(root, 450, 200);
29         scene.setFill(Color.PINK);
30         Text name= new Text("name1");
31         name.setFont(Font.font ("STXingKai", 36));
32         AnchorPane.setTopAnchor(name, 25.0);
33         AnchorPane.setLeftAnchor(name, 50.0);
34         Text name1= new Text("name2");
35         name1.setFont(Font.font ("STXingKai", 36));
36         AnchorPane.setTopAnchor(name1, 75.0);
37         AnchorPane.setLeftAnchor(name1, 50.0);
38         Text name2= new Text("name3");
39         name2.setFont(Font.font ("STXingKai", 36));
40         AnchorPane.setTopAnchor(name2, 125.0);
41         AnchorPane.setLeftAnchor(name2, 50.0);
42         final TextField tf=new TextField();
43         AnchorPane.setTopAnchor(tf, 34.0);
44         AnchorPane.setLeftAnchor(tf, 145.0);
45         final TextField tf1=new TextField();
46         AnchorPane.setTopAnchor(tf1, 84.0);
47         AnchorPane.setLeftAnchor(tf1, 145.0);
48         final TextField tf2=new TextField();
49         AnchorPane.setTopAnchor(tf2, 134.0);
50         AnchorPane.setLeftAnchor(tf2, 145.0);
51         Button button = new Button("OK");
52         AnchorPane.setTopAnchor(button, 134.0);
53         AnchorPane.setLeftAnchor(button, 350.0);
54         button.setOnAction( new EventHandler<ActionEvent>( ) {
55             public void handle(ActionEvent actEvt) {
56                 final String name_ = tf.getText();
57                 final String name_1 = tf1.getText();
58                 final String name_2 = tf2.getText();
59                 if(name_.length()<1||name_.length()>6){
60                     System.out.println("name1长度应为1-6");
61                 }
62                 else if(!isRegularRptCode(name_,"[a-z,A-Z,0-9]*")){
63                     System.out.println("name1字符应为a-z,A-Z,0-9");
64                 }
65                 else{
66                     System.out.println("name1OK");
67                 }
68                 if(name_1.length()<1||name_1.length()>6){
69                     System.out.println("name2长度应为1-6");
70                 }
71                 else if(!isRegularRptCode(name_1,"[a-z,A-Z,0-9]*")){
72                     System.out.println("name2字符应为a-z,A-Z,0-9");
73                 }
74                 else{
75                     System.out.println("name2OK");
76                 }
77                 if(name_2.length()<1||name_2.length()>6){
78                     System.out.println("name3长度应为1-6");
79                 }
80                 else if(!isRegularRptCode(name_2,"[a-z,A-Z,0-9]*")){
81                     System.out.println("name3字符应为a-z,A-Z,0-9");
82                 }
83                 else{
84                     System.out.println("name3OK");
85                 }
86             }
87         } );
88         root.getChildren().addAll(name,name1,name2,tf,tf1,tf2,button);
89         stage.setScene(scene);
90         stage.show();
91     }
92 }
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号