Compare commits
No commits in common. 'main' and 'master' have entirely different histories.
@ -0,0 +1,3 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/jeidui1.iml" filepath="$PROJECT_DIR$/jeidui1.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,119 @@
|
|||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class Main extends Application {
|
||||||
|
private TextField display = new TextField();
|
||||||
|
private Button[] numberButtons = new Button[10];
|
||||||
|
private Button addButton, subtractButton, multiplyButton, divideButton, modulusButton, equalsButton, clearButton;
|
||||||
|
private Label statusLabel = new Label("");
|
||||||
|
|
||||||
|
private SimpleDoubleProperty firstOperand = new SimpleDoubleProperty(0);
|
||||||
|
private SimpleDoubleProperty secondOperand = new SimpleDoubleProperty(0);
|
||||||
|
private String operator = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.CENTER);
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
display.setEditable(false);
|
||||||
|
grid.add(display, 0, 0, 4, 1);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
numberButtons[i] = new Button(String.valueOf(i));
|
||||||
|
grid.add(numberButtons[i], (i % 3), (i / 3) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
addButton = new Button("+");
|
||||||
|
subtractButton = new Button("-");
|
||||||
|
multiplyButton = new Button("*");
|
||||||
|
divideButton = new Button("/");
|
||||||
|
modulusButton = new Button("%");
|
||||||
|
equalsButton = new Button("=");
|
||||||
|
clearButton = new Button("C");
|
||||||
|
|
||||||
|
grid.add(addButton, 3, 1);
|
||||||
|
grid.add(subtractButton, 3, 2);
|
||||||
|
grid.add(multiplyButton, 3, 3);
|
||||||
|
grid.add(divideButton, 3, 4);
|
||||||
|
grid.add(modulusButton, 3, 5);
|
||||||
|
grid.add(equalsButton, 3, 6);
|
||||||
|
grid.add(clearButton, 3, 7);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
int finalI = i;
|
||||||
|
numberButtons[i].setOnAction(e -> display.appendText(String.valueOf(finalI)));
|
||||||
|
}
|
||||||
|
|
||||||
|
addButton.setOnAction(e -> setOperator("+"));
|
||||||
|
subtractButton.setOnAction(e -> setOperator("-"));
|
||||||
|
multiplyButton.setOnAction(e -> setOperator("*"));
|
||||||
|
divideButton.setOnAction(e -> setOperator("/"));
|
||||||
|
modulusButton.setOnAction(e -> setOperator("%"));
|
||||||
|
equalsButton.setOnAction(e -> calculate());
|
||||||
|
clearButton.setOnAction(e -> clear());
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid, 300, 400);
|
||||||
|
primaryStage.setTitle("Calculator");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setOperator(String op) {
|
||||||
|
if (!operator.isEmpty()) {
|
||||||
|
calculate();
|
||||||
|
}
|
||||||
|
operator = op;
|
||||||
|
firstOperand.setValue(Double.parseDouble(display.getText()));
|
||||||
|
display.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculate() {
|
||||||
|
if (!operator.isEmpty()) {
|
||||||
|
secondOperand.setValue(Double.parseDouble(display.getText()));
|
||||||
|
double result = 0;
|
||||||
|
switch (operator) {
|
||||||
|
case "+":
|
||||||
|
result = firstOperand.get() + secondOperand.get();
|
||||||
|
break;
|
||||||
|
case "-":
|
||||||
|
result = firstOperand.get() - secondOperand.get();
|
||||||
|
break;
|
||||||
|
case "*":
|
||||||
|
result = firstOperand.get() * secondOperand.get();
|
||||||
|
break;
|
||||||
|
case "/":
|
||||||
|
if (secondOperand.get() != 0) {
|
||||||
|
result = firstOperand.get() / secondOperand.get();
|
||||||
|
} else {
|
||||||
|
statusLabel.setText("Cannot divide by zero");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "%":
|
||||||
|
result = firstOperand.get() % secondOperand.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
display.setText(String.format("%.2f", result));
|
||||||
|
operator = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clear() {
|
||||||
|
display.clear();
|
||||||
|
firstOperand.setValue(0);
|
||||||
|
secondOperand.setValue(0);
|
||||||
|
operator = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="GENERAL_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,3 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/jeidui1.iml" filepath="$PROJECT_DIR$/jeidui1.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
Binary file not shown.
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="GENERAL_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Loading…
Reference in new issue