Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Java GUI program conveniently for the end user

The user wants to start the Java GUI application from Windows, with some amount of additional JVM parameters.
For instance:

javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

If I add the above line to the batch file, the user can double-click the batch-file name.
And it's cool. But there is one annoying side effect: the batch file opens the cmd window before starting the GUI.

Is there a simple way to start the java GUI application by double-clicking the batch-file (or some other file which suits the above needs) without opening the cmd window?

like image 238
MockerTim Avatar asked Dec 14 '11 13:12

MockerTim


People also ask

What are the methods for GUI?

Commonly Used Methods in All GUI ComponentsString getText(), void setText(String s) -- accessor methods for the text of labels, buttons, text fields and text areas. void setBackground(Color c) -- sets the background color of a component.

What is GUI in Java with examples?

What is GUI in Java? GUI (Graphical User Interface) in Java is an easy-to-use visual experience builder for Java applications. It is mainly made of graphical components like buttons, labels, windows, etc. through which the user can interact with an application.

Can I create UI with Java?

Creating a GUI is a great way to get experience working with objects in Java because each interface component is represented by its own class. To use an interface component in Java, you create an object of that component's class. You already have worked with the container class JFrame.


Video Answer


3 Answers

I see a number of ways:

  • Use a launcher as generated by Launch4J (thanks to CodeBrickie for the tip) or Install4J/Exe4J. Launch4J allows you to tweak the parameters by creating an .l4j.ini file with the same name as the exe. In case of Exe4J, extra parameters can be specified in a .vmoptions file which you drop next to the generated exe.
  • Create a Shortcut to javaw.exe, give it the icon you want, set the "Start in" field to the directory of the application and specify your parameters to javaw in the Target field.
  • Make a VB script which launches javaw. If the VBS runtime is set to use wscript, no console window will pop up.
  • If you use Java Web Start, you might want to let the user tweak the JNLP file as specified in Java Webstart with parameters.
like image 111
JBert Avatar answered Nov 09 '22 18:11

JBert


Try

start javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

You can also use scripting:

VBS:

Const HIDDEN_WINDOW = 12 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set objStartup = objWMIService.Get("Win32_ProcessStartup") 

Set objConfig = objStartup.SpawnInstance_ 
objConfig.ShowWindow = HIDDEN_WINDOW 
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") 
errReturn = objProcess.Create("Notepad.exe", null, objConfig, intProcessID)

JScript:

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c abc.bat", WindowStyle_Hidden)

Finally, there are general-purpose utilities you can use to hide windows, such as CMDOW and Hidden Start ($20). I have not used either myself, since start does the same thing.

like image 39
Allen Z. Avatar answered Nov 09 '22 20:11

Allen Z.


The user wants to start the Java GUI application ..

The best user experience for the end user will be offered by launching the app. using Java Web Start. JWS can install desktop shortcuts and menu items to launch the app.

..from Windows..

JWS also works on OS X & *nix.

like image 20
Andrew Thompson Avatar answered Nov 09 '22 20:11

Andrew Thompson