zoukankan      html  css  js  c++  java
  • 三个输入框测试

     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 }

  • 相关阅读:
    LINQ to XML 操作XML文档
    C#2008与.NET 3.5 高级程序设计读书笔记(3)C#核心编程结构I
    阐述集合类的接口(IEnumerable,IEnumerator,ICollection,IList,IDictionary)
    山塞一个PetShop(Task001)——基本的数据库连接
    山寨一个PetShop(Task002)——数据类库Model
    自定义控件(Task01)——可以设置属性的控件
    ASP.NET连接SQL、Access、Excel数据库(三)——工厂模式
    ASP.NET连接SQL、Access、Excel数据库(一)——什么是ADO.NET
    ASP.NET 2.0 的数据绑定控件概述与区别(GridView、DetailsView、FormView 、Repeater、DataList)
    ASP.NET连接SQL、Access、Excel数据库(二)——连接实例
  • 原文地址:https://www.cnblogs.com/huo722/p/4376247.html
Copyright © 2011-2022 走看看