From 3ad1c31d2eb27bb762fbdd1f63855cb092680ebc Mon Sep 17 00:00:00 2001 From: Eterlaze <1215710470@qq.com> Date: Wed, 9 Oct 2024 16:41:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=9F=E6=AC=A3=E6=A1=A6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Calculater/src/Calculater.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Calculater/src/Calculater.java b/Calculater/src/Calculater.java index 75c0461..580d01f 100644 --- a/Calculater/src/Calculater.java +++ b/Calculater/src/Calculater.java @@ -12,29 +12,25 @@ public class Calculater extends Application { private double firstNumber = 0; private String operator = ""; private boolean startNewNumber = true; - public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { - // Create display label + display = new Label("0.0"); display.setStyle("-fx-font-size: 30px;"); - display.setMinWidth(200); // Adjust width for display - display.setAlignment(Pos.CENTER_RIGHT); // Align text to the right + display.setMinWidth(200); + display.setAlignment(Pos.CENTER_RIGHT); - // Set up the buttons GridPane gridPane = createButtonGrid(); - // Create the layout VBox layout = new VBox(10); layout.setPadding(new Insets(10)); layout.setAlignment(Pos.CENTER); layout.getChildren().addAll(display, gridPane); - // Set up the scene and stage Scene scene = new Scene(layout, 300, 400); primaryStage.setTitle("Calculator"); primaryStage.setScene(scene); @@ -47,7 +43,6 @@ public class Calculater extends Application { grid.setVgap(10); grid.setAlignment(Pos.CENTER); - // Create buttons with a similar layout to your screenshot String[][] buttonText = { {"AC", "±", "%", "÷"}, {"7", "8", "9", "×"}, @@ -56,17 +51,15 @@ public class Calculater extends Application { {"0", ".", "=", ""} }; - // Set button size int buttonSize = 50; - // Add buttons to the grid int row = 0; for (int i = 0; i < buttonText.length; i++) { for (int j = 0; j < buttonText[i].length; j++) { if (!buttonText[i][j].isEmpty()) { Button button = createButton(buttonText[i][j], buttonSize); if (buttonText[i][j].equals("0")) { - grid.add(button, j, row, 2, 1); // Make '0' span two columns + grid.add(button, j, row, 2, 1); } else { grid.add(button, j, row); }