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