前段时间搜索了关于如何用idea打jar包,并用exe4j生成可执行的文件的相关资料。
相关连接:https://blog.csdn.net/inflaRunAs/article/details/90519019
执行exe,打开浏览器并跳转至指定网页。
然后这里是补充,执行exe,显示窗体,可输入参数进行计算。
先放结果:
以下是一个具体的窗体应用的代码:
package com.ruyi.winexe.Checkmod;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
public class winBox extends JFrame implements ActionListener {
//创建面板
private JPanel panel=new JPanel();
//创建标签数组
private JLabel[] labels={new JLabel("时间戳转日期:"),new JLabel("日期转时间戳:")};
//创建输入框数组
private JTextField[] texts = {new JTextField(),new JTextField(),new JTextField(),new JTextField()};
//创建按钮数组
private JButton[] buttons = {new JButton("确定"),new JButton("取消")};
//创建 pattern类型
private JRadioButton[] boxsA = {new JRadioButton("yyyy-MM-dd"),new JRadioButton("yyyy-MM-dd HH:mm:ss")};
private JRadioButton[] boxs2 = {new JRadioButton("yyyy-MM-dd"),new JRadioButton("yyyy-MM-dd HH:mm:ss")};
//创建按钮集合
private ButtonGroup buttonGroup1 = new ButtonGroup();
private ButtonGroup buttonGroup2 = new ButtonGroup();
/**
* 将字符串类型的日期转换为时间戳
* @param dateStr 字符串类型日期
* @param format 日期的格式
* @return
*/
private String dateString2Int(String dateStr, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
return String.valueOf(sdf.parse(dateStr).getTime() / 1000);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 时间戳转日期
* @param timeStamp
* @param pattern
* @return
*/
private String timeStampToDate (Long timeStamp, String pattern) {
Date date = new Date(timeStamp * 1000);
SimpleDateFormat sd = new SimpleDateFormat(pattern);
String result = sd.format(date);
return result;
}
private winBox(){
//初始化面板布局
panel.setLayout(null);
//1. 设置每一个标签尺寸及定位,并装填进面板里
for(int i=0;i<2;i++){
labels[i].setBounds(30, 20+i*60, 100, 30);
panel.add(labels[i]);
}
//2. 设置:确定取消按钮、转换类型按钮、输入框,且进行监听按钮,并装填进面板里
for(int i=0;i<2;i++) {
//设置每一个输入框位置
if(i%2 == 0){
texts[0].setBounds(30, 50+0*60, 230, 26);
texts[2].setBounds(30, 50+1*60, 230, 26);
panel.add(texts[0]);
panel.add(texts[2]);
}else{
texts[1].setBounds(300, 50+0*60, 230, 26);
texts[3].setBounds(300, 50+1*60, 230, 26);
panel.add(texts[1]);
panel.add(texts[3]);
}
//定义确定取消按钮
buttons[i].setBounds(180+i*120, 160, 80, 26);
buttons[i].addActionListener(this);
panel.add(buttons[i]);
//添加时间类型按钮
boxsA[i].setBounds(150+i*155, 20, 155, 30);
boxsA[i].addActionListener(this);
boxs2[i].setBounds(150+i*155, 80, 155, 30);
boxs2[i].addActionListener(this);
buttonGroup1.add(boxsA[i]);
buttonGroup2.add(boxs2[i]);
panel.add(boxsA[i]);
panel.add(boxs2[i]);
}
//3. 添加每一个输入框
for(int i=0;i<4;i++){
panel.add(texts[i]);
}
//4. 设置:向框架内装填面板,及框架属性
this.add(panel);
this.setTitle("时间戳日期转换器");
this.setBounds(100, 110, 564, 250);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* implements ActionListener后生成的监听方法
* @param e 所有被监听元素
*/
public void actionPerformed(ActionEvent e){
if(e.getSource() == buttons[0]){
//如果点击确认,执行计算
String text1 = texts[0].getText();
String text2 = texts[2].getText();
if(!(text1.equals(""))){
String s = null;
if(boxsA[0].isSelected()){
s = timeStampToDate(Long.valueOf(text1), "yyyy-MM-dd");
}else if(boxsA[1].isSelected()) {
s = timeStampToDate(Long.valueOf(text1), "yyyy-MM-dd HH:mm:ss");
}else{
s = "请选择转换类型。";
}
texts[1].setText(s);
}
if(!(text2.equals(""))){
String s = null;
if(boxs2[0].isSelected()){
s = dateString2Int(text2, "yyyy-MM-dd");
}else if(boxs2[1].isSelected()) {
s = dateString2Int(text2, "yyyy-MM-dd HH:mm:ss");
}else{
s = "请选择转换类型。";
}
texts[3].setText(s);
}
}else if(e.getSource() == buttons[1]){
//如果点击取消,清空每一个输入框
for(int i=0;i
之后如何生成exe流程请移步:https://blog.csdn.net/inflaRunAs/article/details/90519019
以上。