每当我双击.JAR文件或从控制台(cmd)运行它时,它会暂时短暂显示然后消失。
我已经编写了一个非常基本的程序,带有GUI,我希望看到它显示出来。 如何让JAR文件对我自己可见?
答案 0 :(得分:1)
试试这可能会对你有所帮助:
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Stackkkk {
public static void main(String[] args) {
JFrame frame =new JFrame();
frame.setSize(500, 200);
frame.setLayout(new FlowLayout());
frame.add(new JLabel("Name"));
JTextField textfield=new JTextField();
textfield.setPreferredSize(new Dimension(100, 50));
frame.add(textfield);
frame.show();
//to stop the the program when jframe is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
创建一个jar文件
答案 1 :(得分:0)
使用以下命令从命令行运行.jar文件:
java -jar path/to/your/File.jar
通过执行此操作,窗口在应用程序完成执行后不会关闭,因此您可以看到任何错误。