IDEA打包成可执行jar包(结合swing做一个小工具)

一、如何打包一个 可执行的jar包

file--project structure--artifacts--"+"---jar--frommodules with dependencies

选择自己的模块,然后选择对应含有main函数的类

 

如果首次设置 这里选择idea所在的目录

 

打包

 

打包好的jar包一般默认放在项目底下会多一个out的文件夹

 

 

demo 

用java swing做一个解密的小工具

package com.swing.decipher.Controller;

import com.swing.decipher.utils.DesUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Base64;

public class demo {
    private static JFrame frame;
    private static  JTextField userText;

    private static JButton loginButton;
    public static void main(String[] args) {
        // 创建 JFrame 实例
        frame = new JFrame("产研解密工具");
        // Setting the width and height of frame
        frame.setSize(450, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* 创建面板,这个类似于 HTML 的 div 标签
         * 我们可以创建多个面板并在 JFrame 中指定位置
         * 面板中我们可以添加文本字段,按钮及其他组件。
         */
        JPanel panel = new JPanel();
        // 添加面板
        frame.add(panel);
        /*
         * 调用用户定义的方法并添加组件到面板
         */
        placeComponents(panel);

        // 设置界面可见
        frame.setVisible(true);

        //设置窗体打开在电脑屏幕居中
        int windowWidth = frame.getWidth(); //获得窗口宽
        int windowHeight = frame.getHeight(); //获得窗口高
        Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包
        Dimension screenSize = kit.getScreenSize(); //获取屏幕的尺寸
        int screenWidth = screenSize.width; //获取屏幕的宽
        int screenHeight = screenSize.height; //获取屏幕的高
        frame.setLocation(screenWidth/2-windowWidth/2, screenHeight/2-windowHeight/2);//设置窗口居中显示
    }

    private static class Button1Handler implements ActionListener {
        public void actionPerformed(ActionEvent e) {

    //自己对应的按钮事件
            //String content = "muhc5/A40WhZWV6CmjUpSOXz2SJlrvQzhxR45zTNNAkC7Y6uVRNGBfrZguONVEcSc1ticOHSnYmjNuLH8bvBugy9CTm5Qykw6Mi+MD7AJPnwXkJGFzfZdL1mC2j9v6H6qQvDt6N5A1xyII0z0QgrVw==";
            String content=userText.getText();
            try {
                byte[] bytes = Base64.getDecoder().decode(content);
                String contentJson = DesUtil.decoderDesOfByte("自己解密对应的key", bytes);
                System.out.println(contentJson);
                if(contentJson==null){
                    JOptionPane.showMessageDialog(frame, "不是正确的加密串");
                }else {
                    JOptionPane.showMessageDialog(frame, contentJson);
                }
            }catch (Exception e1){
                JOptionPane.showMessageDialog(frame, "不是正确的加密串");
            }
        }
    }

    //清空按钮的监听事件
    private static class cleanButtonHandler implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            userText.setText("");
        }
    }

    private static void placeComponents(JPanel panel) {

        /* 布局部分我们这边不多做介绍
         * 这边设置布局为 null
         */
        panel.setLayout(null);

        // 创建 JLabel
        JLabel userLabel = new JLabel("字符串:");
        /* 这个方法定义了组件的位置。
         * setBounds(x, y, width, height)
         * x 和 y 指定左上角的新位置,由 width 和 height 指定新的大小。
         */
        userLabel.setBounds(10,20,65,25);
        panel.add(userLabel);

        /*
         * 创建文本域用于用户输入
         */
        userText = new JTextField(20);
        userText.setBounds(100,20,300,25);
        panel.add(userText);


        // 创建破解按钮
        loginButton = new JButton("破解");
        loginButton.setBounds(10, 80, 80, 25);
        loginButton.addActionListener(new demo.Button1Handler());
        panel.add(loginButton);

        //创建清空按钮
        JButton cleanButton = new JButton("清空");
        cleanButton.setBounds(100, 80, 80, 25);
        cleanButton.addActionListener(new demo.cleanButtonHandler());
        panel.add(cleanButton);
    }

}

关于des解密中用到的工具类详见另一篇博客  https://blog.csdn.net/m0_38121868/article/details/84284699

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值