三个输入框测试

 1 package testclass;
 2 
 3 import java.util.regex.Matcher;
 4 import java.util.regex.Pattern;
 5 import javafx.application.Application;
 6 import javafx.event.ActionEvent;
 7 import javafx.event.EventHandler;
 8 import javafx.scene.Scene;
 9 import javafx.scene.control.Button;
10 import javafx.scene.control.TextField;
11 import javafx.scene.layout.AnchorPane;
12 import javafx.scene.text.Font;
13 import javafx.scene.text.Text;
14 import javafx.stage.Stage;
15  
16 public class test extends Application {
17     public static boolean isRegularRptCode(String rptCode,String regEx) {
18         Pattern pattern1 = Pattern.compile(regEx);
19         Matcher matcher1 = pattern1.matcher(rptCode);
20         boolean rs = matcher1.matches();
21         return rs;
22 }
23 public static void main(String[] args) {
24          test.launch(args);
25 }
26 public void start(Stage stage)throws Exception {
27         stage.setTitle("Edit");
28         AnchorPane root = new AnchorPane();
29         Scene scene = new Scene(root, 500, 200);
30         Text text1= new Text("String one");
31         text1.setFont(new Font(20));
32         AnchorPane.setTopAnchor(text1, 20.0);
33         AnchorPane.setLeftAnchor(text1, 0.0);
34         Text text2= new Text("String two");
35         text2.setFont(new Font(20));
36         AnchorPane.setTopAnchor(text2, 70.0);
37         AnchorPane.setLeftAnchor(text2, 0.0);
38         Text text3= new Text("String three");
39         text3.setFont(new Font(20));
40         AnchorPane.setTopAnchor(text3, 120.0);
41         AnchorPane.setLeftAnchor(text3, 0.0);
42         root.getChildren().addAll(text1,text2,text3);
43         final TextField filed1=new TextField();
44         AnchorPane.setTopAnchor(filed1, 20.0);
45         AnchorPane.setLeftAnchor(filed1, 130.0);
46         final TextField filed2=new TextField();
47         AnchorPane.setTopAnchor(filed2, 70.0);
48         AnchorPane.setLeftAnchor(filed2, 130.0);
49         final TextField filed3=new TextField();
50         AnchorPane.setTopAnchor(filed3, 120.0);
51         AnchorPane.setLeftAnchor(filed3, 130.0);
52         root.getChildren().addAll(filed1,filed2,filed3);
53         Button button = new Button("Press");
54         button.setFont(new Font(20));
55         AnchorPane.setTopAnchor(button, 70.0);
56         AnchorPane.setLeftAnchor(button, 400.0);
57         root.getChildren().addAll(button);
58 
59         button.setOnAction( new EventHandler<ActionEvent>( ) {
60             public void handle(ActionEvent actEvt) {        
61                     final String char1 = filed1.getText();
62                     final String char2 = filed2.getText();
63                     final String char3 = filed3.getText();
64                     if(char1.length()<1||char1.length()>6){System.out.println("String one Wrong");}
65                     else if(!isRegularRptCode(char1,"[a-z,A-Z,0-9]*")){System.out.println("String one Wrong");}
66                     else{System.out.println("String one Right");}
67                     
68                     if(char2.length()<1||char2.length()>6){System.out.println("String two Wrong");}
69                     else if(!isRegularRptCode(char2,"[a-z,A-Z,0-9]*")){System.out.println("String two Wrong");}
70                     else{System.out.println("String two Right");}
71                     
72                     if(char3.length()<1||char3.length()>6){System.out.println("String three Wrong");}
73                     else if(!isRegularRptCode(char3,"[a-z,A-Z,0-9]*")){System.out.println("String three Wrong");}
74                     else{System.out.println("String three Right");}                
75                     }
76                     } );
77     stage.setScene(scene);
78     stage.show();
79     }
80 }

转载于:https://www.cnblogs.com/huo722/p/4376247.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值