当前位置:   article > 正文

【JAVA快速编写UI】 Java 编写一个编码转换和加解密工具,可以创建一个简单的 GUI 应用程序(例子)

【JAVA快速编写UI】 Java 编写一个编码转换和加解密工具,可以创建一个简单的 GUI 应用程序(例子)
EncodingDecodingTool/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── rockmelodies/
│   │   │           └── encodingdecodingtool/
│   │   │               ├── MainApp.java
│   │   │               ├── controller/
│   │   │               │   └── MainController.java
│   │   │               └── util/
│   │   │                   └── CryptoUtils.java
│   │   └── resources/
│   │       └── com/
│   │           └── rockmelodies/
│   │               └── encodingdecodingtool/
│   │                   └── view/
│   │                       ├── main_layout.fxml
│   │                       └── styles.css
└── pom.xml

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
# MainApp.java
package com.rockmelodies.encodingdecodingtool;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MainApp extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/com/rockmelodies/encodingdecodingtool/view/main_layout.fxml"));
        primaryStage.setTitle("Encoding & Decoding Tool");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
# CryptoUtils.java
package com.rockmelodies.encodingdecodingtool;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MainApp extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/com/rockmelodies/encodingdecodingtool/view/main_layout.fxml"));
        primaryStage.setTitle("Encoding & Decoding Tool");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
# MainController
package com.rockmelodies.encodingdecodingtool.controller;

import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import com.rockmelodies.encodingdecodingtool.util.CryptoUtils;

public class MainController {

    @FXML
    private TextField inputField;
    @FXML
    private TextArea outputArea;

    @FXML
    private void handleBase64Encode() {
        String input = inputField.getText();
        String encoded = CryptoUtils.base64Encode(input);
        outputArea.setText(encoded);
    }

    @FXML
    private void handleBase64Decode() {
        String input = inputField.getText();
        String decoded = CryptoUtils.base64Decode(input);
        outputArea.setText(decoded);
    }

    public void switchTheme(String theme) {
        Scene scene = inputField.getScene();
        scene.getStylesheets().clear();
        scene.getStylesheets().add(getClass().getResource("/com/rockmelodies/encodingdecodingtool/view/" + theme + ".css").toExternalForm());
    }


    // Add more handlers for other encoding/decoding and encryption/decryption methods
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

main_layout.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="com.rockmelodies.encodingdecodingtool.controller.MainController">
    <TextField fx:id="inputField" promptText="Enter text here..."/>
    <Button text="Base64 Encode" onAction="#handleBase64Encode"/>
    <Button text="Base64 Decode" onAction="#handleBase64Decode"/>
    <!-- Add more buttons for other encoding/decoding and encryption/decryption methods -->
    <TextArea fx:id="outputArea" editable="false" promptText="Output will appear here..."/>
</VBox>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

styless.css

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="com.rockmelodies.encodingdecodingtool.controller.MainController">
    <TextField fx:id="inputField" promptText="Enter text here..."/>
    <Button text="Base64 Encode" onAction="#handleBase64Encode"/>
    <Button text="Base64 Decode" onAction="#handleBase64Decode"/>
    <!-- Add more buttons for other encoding/decoding and encryption/decryption methods -->
    <TextArea fx:id="outputArea" editable="false" promptText="Output will appear here..."/>
</VBox>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在这里插入图片描述

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/289962
推荐阅读
相关标签
  

闽ICP备14008679号