Javafx 自创小程序

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.stage.Stage;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

import javafx.scene.layout.GridPane;

public class Week5_class extendsApplication {

  Label label =new Label("请输入最大值:");

  TextField TextField1=new TextField("100");

  Button Button=new Button("生成");

  TextField TextField2=new TextField("精彩即将出现");

public void start(StageprimaryStage){//create a sence and place a button in the stage

 GridPane pane=new GridPane();

 Scene scene=new Scene(pane,250,50);

 primaryStage.setScene(scene);

 primaryStage.show();

 pane.add(label,0,0);

pane.add(TextField1,1,0);

pane.add(Button,0,1);

pane.add(TextField2,1,1); 

Button.setOnAction (event->{

       int Max=100;

       int Min=1;

      int num=(int)Math.floor(Math.random()*(Max-Min+1))+Min;  

TextField2.setText(String.valueOf(num));

});

}   

   public static void main(String[] args) {

       

    }

}

你可能感兴趣的:(javafx)