Reputation: 21
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?
Upvotes: 0
Views: 1940
Reputation: 14751
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
Upvotes: 1
Reputation: 1594
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.
Upvotes: 0