diff --git a/.idea/misc.xml b/.idea/misc.xml index 0548357..1f014b5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/.idea/modules.xml b/.idea/modules.xml index d2a818d..1421c22 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/Two/Two.iml b/Two/Two.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Two/Two.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Two/src/Main.java b/Two/src/Main.java new file mode 100644 index 0000000..3e59c38 --- /dev/null +++ b/Two/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Two/src/test1.java b/Two/src/test1.java new file mode 100644 index 0000000..ffe12e8 --- /dev/null +++ b/Two/src/test1.java @@ -0,0 +1,88 @@ +import javafx.application.Application; +import javafx.stage.Stage; +import javafx.application.Application; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.GridPane; +import javafx.stage.Stage; + +public class test1 extends Application { + + @Override + public void start(Stage primaryStage) { + primaryStage.setTitle("进制转换器"); + + // 创建布局 + GridPane grid = new GridPane(); + grid.setPadding(new Insets(10)); + grid.setVgap(8); + grid.setHgap(10); + + // 输入框 + Label inputLabel = new Label("输入数值:"); + GridPane.setConstraints(inputLabel, 0, 0); + TextField inputField = new TextField(); + GridPane.setConstraints(inputField, 1, 0); + + // 源进制选择 + Label fromBaseLabel = new Label("源进制:"); + GridPane.setConstraints(fromBaseLabel, 0, 1); + ComboBox fromBaseCombo = new ComboBox<>(); + fromBaseCombo.getItems().addAll(2, 8, 10, 16); // 添加八进制 + fromBaseCombo.setValue(10); // 默认选择十进制 + GridPane.setConstraints(fromBaseCombo, 1, 1); + + // 目标进制选择 + Label toBaseLabel = new Label("目标进制:"); + GridPane.setConstraints(toBaseLabel, 0, 2); + ComboBox toBaseCombo = new ComboBox<>(); + toBaseCombo.getItems().addAll(2, 8, 10, 16); // 添加八进制 + toBaseCombo.setValue(10); // 默认选择十进制 + GridPane.setConstraints(toBaseCombo, 1, 2); + + // 转换按钮 + Button convertButton = new Button("转换"); + GridPane.setConstraints(convertButton, 1, 3); + + // 输出框 + Label resultLabel = new Label("结果:"); + GridPane.setConstraints(resultLabel, 0, 4); + TextField resultField = new TextField(); + resultField.setEditable(false); + GridPane.setConstraints(resultField, 1, 4); + + // 处理转换逻辑 + convertButton.setOnAction(e -> { + String input = inputField.getText(); + int fromBase = fromBaseCombo.getValue(); + int toBase = toBaseCombo.getValue(); + String result = convertBase(input, fromBase, toBase); + resultField.setText(result); + }); + + // 添加所有控件到布局 + grid.getChildren().addAll(inputLabel, inputField, fromBaseLabel, fromBaseCombo, + toBaseLabel, toBaseCombo, convertButton, resultLabel, resultField); + + // 创建场景并显示 + Scene scene = new Scene(grid, 400, 200); + primaryStage.setScene(scene); + primaryStage.show(); + } + + private String convertBase(String value, int fromBase, int toBase) { + try { + // 将输入值从源进制转换为十进制 + int decimalValue = Integer.parseInt(value, fromBase); + // 将十进制转换为目标进制 + return Integer.toString(decimalValue, toBase).toUpperCase(); + } catch (NumberFormatException e) { + return "输入无效"; + } + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/out/production/One/Main.class b/out/production/One/Main.class new file mode 100644 index 0000000..baa3095 Binary files /dev/null and b/out/production/One/Main.class differ diff --git a/out/production/One/test1.class b/out/production/One/test1.class new file mode 100644 index 0000000..cdbcaa5 Binary files /dev/null and b/out/production/One/test1.class differ diff --git a/out/production/Two/Main.class b/out/production/Two/Main.class new file mode 100644 index 0000000..baa3095 Binary files /dev/null and b/out/production/Two/Main.class differ diff --git a/out/production/Two/test1.class b/out/production/Two/test1.class new file mode 100644 index 0000000..a8fdc51 Binary files /dev/null and b/out/production/Two/test1.class differ