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 class Sfw_test extendsApplication{
AnchorPane root= newAnchorPane();
Scene scene= new Scene(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);final TextField textField = newTextField ();
textField.setPrefWidth(150);
textField.getText();
AnchorPane.setTopAnchor(textField,20.0);
AnchorPane.setLeftAnchor(textField,130.0);final Label label1 = new Label(" ");
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(new EventHandler() {
@Overridepublic voidhandle(ActionEvent e) {
String year=textField.getText().toString();boolean inputlegal = false;int Isleapyear = 2;for (int i=0; i
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");
}
}
});
root.getChildren().addAll(textField,text,submit,label1);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
}