Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -1,29 +0,0 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
@ -1,6 +0,0 @@
|
||||
<?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>
|
||||
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/demoForCaculator.iml" filepath="$PROJECT_DIR$/demoForCaculator.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,11 +0,0 @@
|
||||
<?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>
|
||||
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<VBox alignment="CENTER" spacing="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="CalculatorController">
|
||||
<padding>
|
||||
<Insets left="20.0" right="20.0" top="20.0"/>
|
||||
</padding>
|
||||
<HBox alignment="CENTER" spacing="10.0">
|
||||
<TextField fx:id="number1Field" alignment="CENTER" promptText="Enter first number" />
|
||||
<ChoiceBox fx:id="operatorChoiceBox" />
|
||||
<TextField fx:id="number2Field" alignment="CENTER" promptText="Enter second number" />
|
||||
<Button text="=" onAction="#handleCalculateAction" />
|
||||
</HBox>
|
||||
<Label fx:id="resultLabel" />
|
||||
</VBox>
|
||||
@ -1,24 +0,0 @@
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class Caculator extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
URL url = getClass().getResource("Caculator.fxml");
|
||||
VBox root = FXMLLoader.load(url);
|
||||
Scene scene = new Scene(root);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("模拟计算器");
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
public class CalculatorController {
|
||||
|
||||
@FXML
|
||||
private TextField number1Field;
|
||||
|
||||
@FXML
|
||||
private ChoiceBox<String> operatorChoiceBox;
|
||||
|
||||
@FXML
|
||||
private TextField number2Field;
|
||||
|
||||
@FXML
|
||||
private Label resultLabel;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
// 初始化运算符下拉菜单
|
||||
operatorChoiceBox.getItems().addAll("+", "-", "*", "/", "%");
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleCalculateAction() {
|
||||
try {
|
||||
double number1 = Double.parseDouble(number1Field.getText());
|
||||
double number2 = Double.parseDouble(number2Field.getText());
|
||||
String operator = operatorChoiceBox.getValue();
|
||||
|
||||
double result = 0;
|
||||
switch (operator) {
|
||||
case "+":
|
||||
result = number1 + number2;
|
||||
break;
|
||||
case "-":
|
||||
result = number1 - number2;
|
||||
break;
|
||||
case "*":
|
||||
result = number1 * number2;
|
||||
break;
|
||||
case "/":
|
||||
if (number2 != 0) {
|
||||
result = number1 / number2;
|
||||
} else {
|
||||
throw new ArithmeticException("Division by zero");
|
||||
}
|
||||
break;
|
||||
case "%":
|
||||
if (number2 != 0) {
|
||||
result = number1 % number2;
|
||||
} else {
|
||||
throw new ArithmeticException("Division by zero");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid operator");
|
||||
}
|
||||
resultLabel.setText(String.valueOf(result));
|
||||
} catch (Exception e) {
|
||||
resultLabel.setText("Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue