parent
7e3c3431cf
commit
ecf1d20e60
@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,11 @@
|
||||
<?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$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -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$/.idea/lesson1.iml" filepath="$PROJECT_DIR$/.idea/lesson1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,52 @@
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class text1 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
// 创建文本输入框
|
||||
TextField inputField = new TextField();
|
||||
inputField.setPromptText("输入一个十进制数");
|
||||
|
||||
// 创建标签显示结果
|
||||
Label binaryLabel = new Label();
|
||||
Label octalLabel = new Label();
|
||||
Label hexLabel = new Label();
|
||||
|
||||
// 创建按钮
|
||||
Button convertButton = new Button("转换");
|
||||
convertButton.setOnAction(e -> {
|
||||
try {
|
||||
int number = Integer.parseInt(inputField.getText());
|
||||
binaryLabel.setText(String.format("二进制: %s", Integer.toBinaryString(number).toUpperCase()));
|
||||
octalLabel.setText(String.format("八进制: %s", Integer.toOctalString(number)));
|
||||
hexLabel.setText(String.format("十六进制: %s", Integer.toHexString(number).toUpperCase()));
|
||||
} catch (NumberFormatException ex) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("输入错误");
|
||||
alert.setHeaderText("无效输入");
|
||||
alert.setContentText("请输入一个有效的十进制数。");
|
||||
alert.showAndWait();
|
||||
}
|
||||
});
|
||||
|
||||
// 创建布局
|
||||
VBox vBox = new VBox(10);
|
||||
vBox.getChildren().addAll(inputField, convertButton, binaryLabel, octalLabel, hexLabel);
|
||||
|
||||
// 设置场景
|
||||
Scene scene = new Scene(vBox, 300, 200);
|
||||
|
||||
primaryStage.setTitle("进制转换器");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue