Compare commits

...

No commits in common. 'master' and 'main' have entirely different histories.
master ... main

@ -2,8 +2,9 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/1/1.iml" filepath="$PROJECT_DIR$/1/1.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/cwxzds.iml" filepath="$PROJECT_DIR$/.idea/cwxzds.iml" />
<module fileurl="file://$PROJECT_DIR$/test/test.iml" filepath="$PROJECT_DIR$/test/test.iml" />
<module fileurl="file://$PROJECT_DIR$/qq/qq.iml" filepath="$PROJECT_DIR$/qq/qq.iml" />
</modules>
</component>
</project>

@ -0,0 +1,95 @@
package Calculator;
import javax.swing.*;
public class Calculator {
// 加法
public static double add(double a, double b) {
return a + b;
}
// 减法
public static double subtract(double a, double b) {
return a - b;
}
// 乘法
public static double multiply(double a, double b) {
return a * b;
}
// 除法
public static double divide(double a, double b) {
if (b == 0) {
throw new ArithmeticException("Cannot divide by zero.");
}
return a / b;
}
// 取余
public static double modulus(double a, double b) {
if (b == 0) {
throw new ArithmeticException("Cannot take modulus by zero.");
}
return a % b;
}
public static void main(String[] args) {
String input1, input2, operator;
double num1, num2, result;
while (true) {
input1 = JOptionPane.showInputDialog("请输入第一个数字 (或输入 'exit' 退出):");
if (input1 == null || input1.equalsIgnoreCase("exit")) {
JOptionPane.showMessageDialog(null, "计算器已退出。");
break; // 退出循环
}
try {
num1 = Double.parseDouble(input1);
operator = JOptionPane.showInputDialog("请输入操作符 (+, -, *, /, %):");
if (operator == null) {
JOptionPane.showMessageDialog(null, "计算器已退出。");
break;
}
input2 = JOptionPane.showInputDialog("请输入第二个数字:");
if (input2 == null) {
JOptionPane.showMessageDialog(null, "计算器已退出。");
break;
}
num2 = Double.parseDouble(input2);
switch (operator) {
case "+":
result = add(num1, num2);
break;
case "-":
result = subtract(num1, num2);
break;
case "*":
result = multiply(num1, num2);
break;
case "/":
result = divide(num1, num2);
break;
case "%":
result = modulus(num1, num2);
break;
default:
JOptionPane.showMessageDialog(null, "无效的操作符!");
continue; // 继续下一次循环
}
JOptionPane.showMessageDialog(null, "结果: " + String.format("%.2f", result));
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "请输入有效的数字!");
} catch (ArithmeticException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}
}

@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cwxzds" vcs="Git" />
</component>
</project>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,2 @@
# cwxzds

@ -1 +0,0 @@
Subproject commit 0bd91ea7154d1914f57f4aba5f89a53e2e106ff7

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,60 @@
package qw;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
public class Calculator extends Application { private double result = 0; private String operator = "";
private boolean start = true; // 用于判断是否开始新的输入
//aaaa
//bbb
private TextField display;
// 显示框
public static void main(String[] args) {
launch(args);
} @Override public void start(Stage primaryStage) { primaryStage.setTitle("计算器"); // 创建显示框
display = new TextField(); display.setEditable(false);
display.setStyle("-fx-font-size: 32px;" +
" -fx-alignment: CENTER_RIGHT;" +
" -fx-padding: 10;");
display.setAlignment(Pos.CENTER_RIGHT); // 创建按钮
Button[] numberButtons = new Button[10];
for (int i = 0; i < 10; i++) { numberButtons[i] = createNumberButton(String.valueOf(i)); } Button addButton = createOperatorButton("+"); Button subButton = createOperatorButton("-"); Button mulButton = createOperatorButton("×");
Button divButton = createOperatorButton("÷");
Button modButton = createOperatorButton("%");
Button equalButton = createEqualButton("=");
Button clearButton = createClearButton("C"); // 创建布局
GridPane grid = new GridPane();
grid.setPadding(new Insets(20));
grid.setVgap(15); grid.setHgap(15); // 将按钮添加到布局
grid.add(display, 0, 0, 4, 1); grid.add(numberButtons[7], 0, 1);
grid.add(numberButtons[8], 1, 1); grid.add(numberButtons[9], 2, 1); grid.add(divButton, 3, 1);
grid.add(numberButtons[4], 0, 2); grid.add(numberButtons[5], 1, 2); grid.add(numberButtons[6], 2, 2);
grid.add(mulButton, 3, 2);
grid.add(numberButtons[1], 0, 3);
grid.add(numberButtons[2], 1, 3);
grid.add(numberButtons[3], 2, 3);
grid.add(subButton, 3, 3);
grid.add(clearButton, 0, 4);
grid.add(numberButtons[0], 1, 4);
grid.add(equalButton, 2, 4);
grid.add(addButton, 3, 4);
grid.add(modButton, 3, 5);
for (Button button : numberButtons) { button.setPrefSize(70, 70);
button.setStyle("-fx-font-size: 24px; -fx-background-color: #87CEFA;");
} addButton.setPrefSize(70, 70);
subButton.setPrefSize(70, 70);
mulButton.setPrefSize(70, 70);
divButton.setPrefSize(70, 70);
modButton.setPrefSize(70, 70);
equalButton.setPrefSize(70, 70);
clearButton.setPrefSize(70, 70);
// 设置操作符按钮样式
addButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FFD700;");
subButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FFD700;");
mulButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FFD700;");
divButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FFD700;");
modButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FFD700;"); equalButton.setStyle("-fx-font-size: 24px; -fx-background-color: #32CD32; -fx-text-fill: white;"); clearButton.setStyle("-fx-font-size: 24px; -fx-background-color: #FF6347; -fx-text-fill: white;"); // 设置窗口大小 Scene scene = new Scene(grid, 400, 500); primaryStage.setScene(scene); primaryStage.show(); } private Button createNumberButton(String number) { Button button = new Button(number); button.setStyle("-fx-font-size: 24px;"); button.setOnAction(e -> handleNumberInput(number)); return button; } private Button createOperatorButton(String operator) { Button button = new Button(operator); button.setStyle("-fx-font-size: 24px;"); button.setOnAction(e -> handleOperatorInput(operator)); return button; }

@ -1,2 +0,0 @@
public class jsq {
}
Loading…
Cancel
Save