标签:
import javax.swing.JOptionPane; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class task extends Application { public static void main(String[] args) { // TODO Auto-generated method stub task.launch( args ); } private TextField textfield = new TextField(); @Override public void start(Stage arg0) throws Exception { // TODO Auto-generated method stub arg0.setTitle( "Testing" ); HBox hbox = new HBox( 8 ); textfield.setPrefColumnCount( 25 ); hbox.setAlignment( Pos.CENTER_LEFT ); Button btn = new Button(); btn.setText( "提交" ); btn.setOnAction( new Listener() ); hbox.getChildren().addAll( new Label( " 请输入年份: "), textfield, btn ); arg0.setScene( new Scene( hbox, 460, 50 )); arg0.show(); } public class Listener implements EventHandler<ActionEvent> { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub String str = textfield.getText(); String inf = ""; if( isLeap( Integer.parseInt( str ) ) ) { inf = "输入年份为闰年"; } else { inf = "输入年份非闰年"; } JOptionPane.showMessageDialog( null, inf, "information", JOptionPane.INFORMATION_MESSAGE ); } } private boolean isLeap( int year ) { if( year % 4 != 0 ) { return false; } else if( year % 100 != 0 ) { return true; } else if( year % 400 != 0 ) { return false; } else { return true; } } }
编号 | 输入 | 预测输出 | |
1 | 1963 | 不能被4整除 | 输入年份非闰年 |
2 | 1964 | 能被4整除但是不能被100整除 | 输入年份为闰年 |
3 | 1900 | 能被4整除能被100整除但是不能被400整除 | 输入年份非闰年 |
4 | 2000 | 能被400整除 | 输入年份为闰年 |
标签:
原文地址:http://www.cnblogs.com/tju-crab/p/4394885.html