gpt4 book ai didi

java - 如何导出为可运行的桌面应用程序java?

转载 作者:行者123 更新时间:2023-12-01 18:49:28 24 4
gpt4 key购买 nike

我已经使用 eclipse 导出并将其导出为 jar 文件,但它在 eclipse 测试运行中工作正常,但不能作为 jar 文件工作,有人可以帮助我吗? (我是 java 新手,这是我的第一个应用程序)

package com.java.folder;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;

public class javafolder extends JApplet implements ActionListener{
private String textLine = "";
JButton b1, b2;
TextField text1, text2;
Container content = getContentPane();

public void init() {
text1 = new TextField(8);
text2 = new TextField(8);
JLabel label = new JLabel("Folder Name");
label.setFont(new Font("Serif", Font.PLAIN, 12));
content.add(label);
add(text1);

content.setBackground(Color.white);
content.setLayout(new FlowLayout());

b1 = new JButton("Creat A Folder");
b1.addActionListener(this);
content.add(b1);

b2 = new JButton("Creat A Folder");
b2.addActionListener(this);
//content.add(b2);
}

// Called when the user clicks the button
public void actionPerformed(ActionEvent event) {
String s;
textLine = event.getActionCommand();
s = text1.getText();
String path = System.getProperty("user.dir");
File dir=new File(path+"/"+s);
if(dir.exists()){
JOptionPane.showMessageDialog(null, "Folder Name Already Exists!!! :(", "Error",
JOptionPane.ERROR_MESSAGE);

}else{
dir.mkdir();
JOptionPane.showMessageDialog(null, "Folder Created :) Folder path:"+dir, "INFORMATION_MESSAGE",
JOptionPane.INFORMATION_MESSAGE);
}
}

}

最佳答案

右键单击您的项目 -> 导出 -> Java -> 可运行的 JAR 文件

从命令行:

java -jar myJar.jar

关于java - 如何导出为可运行的桌面应用程序java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16276192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com