Importjavafx.application.Application;Importjavafx.event.ActionEvent;ImportJavafx.event.EventHandler;ImportJavafx.scene.Scene;ImportJavafx.scene.control.Button;ImportJavafx.scene.control.Label;ImportJavafx.scene.control.TextField;ImportJavafx.scene.layout.AnchorPane;ImportJavafx.scene.text.Font;ImportJavafx.scene.text.Text;ImportJavafx.stage.Stage; Public classSfw_testextendsapplication{Anchorpane Root=NewAnchorpane (); Scene Scene=NewScene (Root, 400, 120); Public Static voidMain (string[] args) {application.launch (args); } Public voidStart (stage stage) {Stage.settitle ("Leapyear Test"); Text text=NewText (); Text.settext ("Input the Year:"); Text.setfont (Font.font ("", 15)); Anchorpane.settopanchor (text,20.0); Anchorpane.setleftanchor (text,10.0); FinalTextField TextField =NewTextField (); Textfield.setprefwidth (150); Textfield.gettext (); Anchorpane.settopanchor (TextField,20.0); Anchorpane.setleftanchor (TextField,130.0); FinalLabel Label1 =NewLabel (""); Label1.setfont (Font.font ("BLACK", 16)); Anchorpane.settopanchor (Label1,60.0); Anchorpane.setleftanchor (Label1,10.0); Button Submit=NewButton (); Submit.settext ("Submit"); Anchorpane.settopanchor (Submit,20.0); Anchorpane.setleftanchor (Submit,300.0); Submit.setonaction (NewEventhandler<actionevent>() {@Override Public voidhandle (ActionEvent e) {String year=Textfield.gettext (). toString (); BooleanInputlegal =false; intIsleapyear = 2; for(inti=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 ()+ "isn't a leap year"); } Else if(Isleapyear = = 1) {Label1.settext (Textfield.gettext ()+ "is a leap year"); } } }); Root.getchildren (). AddAll (TEXTFIELD,TEXT,SUBMIT,LABEL1); Stage.setresizable (false); Stage.setscene (Scene); Stage.show (); }}
The program tests are as follows:
A leap year test program for Java implementations