金安民 1 month ago
parent f1fa110b9a
commit 985cd42543

@ -1,4 +1,4 @@
package Calculator;
package Calculator.jzzh;
import javafx.application.Application;
import javafx.geometry.Insets;
@ -52,9 +52,15 @@ public class CalculatorAPP extends Application {
// 为按钮添加事件监听器
convertButton.setOnAction(e -> {
try {
String num = numberField.getText();
int fromBase = Integer.parseInt(fromBaseField.getText());
int toBase = Integer.parseInt(toBaseField.getText());
String num = numberField.getText().trim();
int fromBase = Integer.parseInt(fromBaseField.getText().trim());
int toBase = Integer.parseInt(toBaseField.getText().trim());
// 验证输入的有效性
if (fromBase < 2 || fromBase > 16 || toBase < 2 || toBase > 16) {
resultLabel.setText("进制范围应在2到16之间。");
return;
}
// 调用转换方法
String converted = convertBase(num, fromBase, toBase);

Loading…
Cancel
Save