钟欣桦修改结果

main
Eterlaze 10 months ago
parent 9e0e656e47
commit 3ad1c31d2e

@ -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);
}

Loading…
Cancel
Save