import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
public class HelloWorld extends Application {
@Override
public void start(Stage stage) {
//creating label email
Text text1 = new Text("a");
//creating label password
Text text2 = new Text("b");
//creating label password
Text text3 = new Text("a+b=c");
//Creating Text Filed for email
TextField textField1 = new TextField();
//Creating Text Filed for password
TextField textField2 = new TextField();
//Creating Text Filed for password
Text textField3 = new Text("");
//Creating Buttons
Button button1 = new Button("Add");
Button button2 = new Button("Clear");
button1.setOnMouseClicked((new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
Integer sum = Integer.parseInt(textField1.getText())+Integer.parseInt(textField2.getText());
textField3.setText(
sum.toString()
);
}
}));
button2.setOnMouseClicked((new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
textField1.setText("");
textField2.setText("");
textField3.setText("");
}
}));
//Creating a Grid Pane
GridPane gridPane = new GridPane();
//Setting size for the pane
gridPane.setMinSize(400, 200);
//Setting the padding
gridPane.setPadding(new Insets(10, 10, 10, 10));
//Setting the vertical and horizontal gaps between the columns
gridPane.setVgap(5);
gridPane.setHgap(5);
//Setting the Grid alignment
gridPane.setAlignment(Pos.CENTER);
//Arranging all the nodes in the grid
gridPane.add(text1, 0, 0);
gridPane.add(textField1, 1, 0);
gridPane.add(text2, 0, 1);
gridPane.add(textField2, 1, 1);
gridPane.add(text3, 0, 2);
gridPane.add(textField3, 1, 2);
gridPane.add(button1, 0, 3);
gridPane.add(button2, 1, 3);
//Styling nodes
button1.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
button2.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
text1.setStyle("-fx-font: normal bold 20px 'serif' ");
text2.setStyle("-fx-font: normal bold 20px 'serif' ");
text3.setStyle("-fx-font: normal bold 20px 'serif' ");
gridPane.setStyle("-fx-background-color: BEIGE;");
//Creating a scene object
Scene scene = new Scene(gridPane);
//Setting title to the Stage
stage.setTitle("a+b=c");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
另外
你說你爬很多文章
我敢說你沒有爬到這篇