zoukankan      html  css  js  c++  java
  • 闰年检验

    闰年检验

    相关代码:

    package test1;

     

    import java.util.regex.Matcher;

    import java.util.regex.Pattern;

    import javafx.application.Application;

    import javafx.event.ActionEvent;

    import javafx.event.EventHandler;

    import javafx.scene.Scene;

    import javafx.scene.control.Button;

    import javafx.scene.control.TextField;

    import javafx.scene.layout.AnchorPane;

    import javafx.scene.paint.Color;

    import javafx.scene.text.Font;

    import javafx.scene.text.Text;

    import javafx.stage.Stage;

     

    public class test02 extends Application {

        public static boolean isRegularRptCode(String rptCode,String regEx) {

            Pattern p1 = Pattern.compile(regEx);

            Matcher m1 = p1.matcher(rptCode);

            boolean rs1 = m1.matches();

            return rs1;

        }

        public static void main(String[] args) {

            test02.launch(args);

        }

        public void start(Stage stage)throws Exception {

           

            stage.setTitle("TEST");

            AnchorPane root = new AnchorPane();

            Scene scene = new Scene(root, 500, 500);

            scene.setFill(Color.WHITE);

           

            Text usename= new Text("输入:");

            usename.setFont(Font.font ("Serif", 28));

            AnchorPane.setTopAnchor(usename, 100.0);

            AnchorPane.setLeftAnchor(usename, 50.0);

           

            Text tips= new Text("验证:");

            tips.setFont(Font.font ("Serif", 28));

            AnchorPane.setTopAnchor(tips, 150.0);

            AnchorPane.setLeftAnchor(tips, 50.0);

           

           

            final TextField textblock=new TextField();

            AnchorPane.setTopAnchor(textblock, 105.0);

            AnchorPane.setLeftAnchor(textblock, 200.0);

           

            final TextField textblock2=new TextField();

            AnchorPane.setTopAnchor(textblock2, 155.0);

            AnchorPane.setLeftAnchor(textblock2, 200.0);

           

            Button button = new Button("检验");

            AnchorPane.setTopAnchor(button, 405.0);

            AnchorPane.setRightAnchor(button, 50.0);

           

            button.setOnAction( new EventHandler<ActionEvent>( ) {

                public void handle(ActionEvent actEvt) {       

                    final String input1;

                    input1 = textblock.getText();

                    //1

                   

                    if(!isRegularRptCode(input1,"[0-9]*")){

                        textblock2.setText("er1: 字符应为数字");

                    }

                    else{

                        int year;

                        year = Integer.parseInt(input1);

                        if((year % 4 == 0 && year % 100 != 0) || year%400==0)

                           textblock2.setText("闰年");

                        else{

                           textblock2.setText("非闰年");

                        }

                    }

                  

                }

            } );

            root.getChildren().addAll(usename,tips,button,

                   textblock,textblock2);

            stage.setScene(scene);

            stage.show();

        }

    }

    相关截图:

  • 相关阅读:
    高效存储过程分页
    c#函数参数
    MonoRail学习:可重复组件ViewComponents的使用
    跨域SSO的实现
    WebSockets基础
    NVelocity用法
    MonoRail MVC应用(2)-构建多层结构的应用程序
    MonoRail学习-入门实例篇
    关于transform属性导致字体模糊的问题
    在小程序中实现收缩展开
  • 原文地址:https://www.cnblogs.com/wangdongT-T/p/4399690.html
Copyright © 2011-2022 走看看