multiplication
Typer | Posted on | |
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Multi extends Application {
@Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
grid.setPadding(new Insets(25));
grid.setHgap(20);
grid.setVgap(12);
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= row; col++) {
String formula = col + " × " + row + " = " + (col * row);
Text text = new Text(formula);
text.setFont(Font.font("Monospaced", FontWeight.BOLD, 15));
text.setFill(Color.DARKSLATEBLUE);
grid.add(text, col - 1, row - 1);
}
}
Scene scene = new Scene(grid, Color.FLORALWHITE);
primaryStage.setTitle("JavaFX 自动适配乘法表");
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
static void main(String[] args) {
launch(args);
}
}