Java-based leap year testing

Source: Internet
Author: User

The following is the test code, to achieve the test input is legitimate and whether it is a leap year (four years a leap, a century does not leap, 400 years to leap):

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.label;import Javafx.scene.control.textfield;import Javafx.scene.layout.anchorpane;import Javafx.scene.text.font;import Javafx.scene.text.text;import Javafx.stage.stage;public class Sfw_test extends Application{anchorpane root = new Anchorpane (); Scene scene = new Scene (root, 550, N);p ublic static void Main (string[] args) {application.launch (args);} public void start (stage stage) {Stage.settitle ("leapyear testing"); Text Texttitle = new text (), Texttitle.settext ("Leapyear TEST"), Texttitle.setfont (Font.font ("BLACK", 57)); Anchorpane.settopanchor (Texttitle, 10.0); Anchorpane.setleftanchor (Texttitle, 10.0); Text text = new text (); Text.settext ("Enter The Year for testing:"); Text.setfont (Font.font ("BLACK", 20)); Anchorpane.settopanchor (text, 90.0); Anchorpane.setleftanchor (text, 10.0); final TextField TextfielD = new TextField (); Textfield.setprefwidth (); Textfield.gettext (); Anchorpane.settopanchor (TextField, 90.0); Anchorpane.setleftanchor (TextField, 330.0); final label Label1 = new Label ("This is a use for show the result ..."); Label1. SetFont (Font.font ("BLACK", 16)); Anchorpane.settopanchor (Label1, 200.0); Anchorpane.setleftanchor (Label1, 10.0); button Submit = New button (); Submit.settext ("submit"); Anchorpane.settopanchor (Submit, 130.0); Anchorpane.setleftanchor (Submit, 330.0); Button clear = New button (); Clear.settext ("clear"); Anchorpane.settopanchor (Clear, 130.0); Anchorpane.setleftanchor (Clear, 420.0); Submit.setonaction (new eventhandler<actionevent> () {@Override public  void handle (ActionEvent e) {String year = Textfield.gettext (). ToString (); Boolean inputlegal = False;int isleapyear = 2;for (int i=0; i<year.length (); i++)                    {if (Year.indexof (Year.charat (i)) = =-1) {Inputlegal = false; }}if (DoublE.valueof (year)%4!=0) {isleapyear = 0;} else if (double.valueof (year)%100==0 && double.valueof (year)%400==0) {isleapyear = 1;} else{isleapyear = 0;}        if (isleapyear = = 0) {Label1.settext (Textfield.gettext () + "is not a leap year");        } else if (isleapyear = = 1) {Label1.settext (Textfield.gettext () + "is a leap year"); }}         }); Clear.setonaction (New eventhandler<actionevent> () {@Override public void handle (ActionEvent e) {TextField        . Clear ();    Label1.settext ("This", "use for show the result ..."); }}); Root.getchildren (). AddAll (Texttitle,text,textfield,submit,clear,label1); stage.setresizable (false); Stage.setscene (scene); Stage.show ();}}

  

The code runs tests as follows:

Java-based leap year testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.