Whenever I double click a .JAR file OR run it from the console (cmd) it appears briefly for a split second and then disappears.
I have written a very basic program, with a GUI, and I was hoping to see it displayed. How do I make the JAR file visible for myself?
try this it may help you :
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);
}
}
create a jar file
Run the .jar file from the command line, using:
java -jar path/to/your/File.jar
By doing this, the window won't close after the application finishes executing so you can see any errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.