Hi everyone, I've been trying to turn one of my programs into an executable application, but every time I click the jar file or open it using the command prompt nothing happens. I was wondering if I shouldn't be using "System.out.println" and Scanners to take input/display output. I am using NetBeans and as far as I can tell it is all in working order.

Recommended Answers

All 6 Replies

If your program only uses the console for input and output then this is a problem. The standard setup for running a jar is to use javaw.exe, which does not display a command window or console. Try running your jar from a command prompt with java.exe instead of javaw.exe That will confirm tha the jar is OK.
To run a jar normally you will have to use something other than the console, eg simple Swing dialog boxes.

Ok I will try that, thanks very much!

What is the appropriate swing class to take user input? I can't seem to find any fitting ones in the javax.swing package

To take user input you need to use the java.awt.event, Then create an action listener to handle any user interaction.

swing class to take user input?

If from the console window, the Scanner class is easy to use.
If from a dialog window, a JOptionPane could be used.
If from an input field in a JFrame, a text field could be used.

If you're not familiar with Swing then a full frame/textfield/event handler will be quite a learning curve. It's one you will need to do sooner or later, so it's up to you.
The JOptionPane solution is the easiest solution. In its very simplest form all you need is

     String answer = JOptionPane.showInputDialog(null, "What is your name?");
     JOptionPane.showMessageDialog(null, "Hello " + answer);

... but you will find lots more examples and details in the API doc for JOptionPane.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.