进制转换

main^2
LIN 1 month ago
parent b3621b4905
commit 1eed805854

@ -18,7 +18,7 @@ public class BaseConverterApp extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Base Converter");
primaryStage.setTitle("进制转换");
// 创建网格布局
GridPane grid = new GridPane();
@ -27,13 +27,13 @@ public class BaseConverterApp extends Application {
grid.setHgap(10);
// 创建输入框
Label inputLabel = new Label("Input Number:");
Label inputLabel = new Label("输入数字:");
grid.add(inputLabel, 0, 0);
inputField = new TextField();
grid.add(inputField, 1, 0);
// 创建“From Base”下拉菜单
Label fromBaseLabel = new Label("From Base:");
Label fromBaseLabel = new Label("转换前进制:");
grid.add(fromBaseLabel, 0, 1);
fromBaseBox = new ComboBox<>();
for (int i = 2; i <= 16; i++) {
@ -43,7 +43,7 @@ public class BaseConverterApp extends Application {
grid.add(fromBaseBox, 1, 1);
// 创建“To Base”下拉菜单
Label toBaseLabel = new Label("To Base:");
Label toBaseLabel = new Label("转换后进制:");
grid.add(toBaseLabel, 0, 2);
toBaseBox = new ComboBox<>();
for (int i = 2; i <= 16; i++) {
@ -53,14 +53,14 @@ public class BaseConverterApp extends Application {
grid.add(toBaseBox, 1, 2);
// 创建结果框
Label resultLabel = new Label("Result:");
Label resultLabel = new Label("结果:");
grid.add(resultLabel, 0, 3);
resultField = new TextField();
resultField.setEditable(false); // 结果框为只读
grid.add(resultField, 1, 3);
// 创建转换按钮
Button convertButton = new Button("Convert");
Button convertButton = new Button("转换");
convertButton.setOnAction(e -> convert());
grid.add(convertButton, 0, 4, 2, 1);
@ -87,7 +87,7 @@ public class BaseConverterApp extends Application {
resultField.setText(result);
} catch (NumberFormatException ex) {
// 如果输入无效,显示错误信息
resultField.setText("Invalid Input");
resultField.setText("输入格式错误");
}
}
}

Loading…
Cancel
Save