This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I wrote a small Tic-Tac-Toe game as a standalone Java application. When I run it, a dos window comes open and stays open under the game. When I exit, the window closes. Is this the Java Console for standalone apps? What is it? How do I use/control it, and what is its purpose? ------------------ ���
Fair enough. Are there methods to control this window? For example, as you mentioned, it is usually hidden for applets. Can I hide it for a standalone application? If I go out and buy an off-the-shelf Java application, will I still have to look at this DOS window while I run it? It just seemed sort of unfinished and unprofessional looking to have that on screen. ------------------ ���
No, you can't. The problem is that java.exe opens this window (acutually, because it is not a GUI application, but a console one). By closing this window you will destroy the JVM itself, since it's his controlling window. The source of this problem may lay in Unix OS, where any application can be started from a console or from another application, who will take care for any ouput produced by child application. If you expirienced with windows programming you can try calling java.exe from an external program, like wrapper to redirect stdout/stderr. I am not sure it is possible in windows, though.
------------------ With best of best regards, Pawel S. Veselov ( aka Black Angel )
With best of best regards, Pawel S. Veselov ( aka Black Angel )
I don't know the exact details (I'm usually the Java specialist, and someone else wrestles with Microsoft), but it is possible for a Windows program to hide and/or minimize a DOS window, or operate as a GUI application and not bother with one. Either find a Windows app that's written in Java and work out how it does it, find a Windows/Java expert who's done it, or spend a lot of time and experimentation with books and web sites.
Ok, I went to Sun's site and downloaded the Swing demos for 1.1.1. The demos are all .EXE's!! How is this accomplished? I just wanted to look at their source to see how they got around the goofy DOS window. ------------------ ���
Joined: Nov 22, 2008
I was out tooling around on java.sun.com and I found this reply to a bulletin board posting: ...This solution works for the older JDK's (our application runs on JDK 1.1.8, though it should work with 1.02 or 1.2.x as well), and Windows 95/98/NT. To install our Java application, we have the users copy a directory from a CD to their local drives. (You can also zip everything up into one zip file for distribution.) The directory has a bin and a lib subdirectory containing the jre. Also in the directory is a jar file containing all of the application's class files, and a batch file. The user runs the program by double-clicking the batch file from Explorer. You can also make a shortcut of the batch file, and put it on the desktop or in the Start menu. Either way, the Java application runs WITHOUT an unneeded DOS frame! Here's how the batch file is set up to do its magic: Contents of the 2-line run.bat: @echo off @start bin\jrew -classpath lib\classes.zip;.\myJarFile.jar MyMainClass When you run the batch file, it briefly launches a DOS frame, which immediately completes its business and closes itself. The Java application appears shortly afterward in its own java.awt.Frame. Notes: To get the DOS frame to disappear automatically in Windows 95/98, you MUST do the @echo off part. The DOS frame won't go away if it's displaying any text. Windows NT doesn't have this problem. The "start" command spawns the java application off in its own DOS interpreter. This allows the batch file to "keep on going", and finish up without waiting for our java application to terminate. Once the batch file is done, the DOS window is able to close on its own. For those who don't know, jre.exe works essentially the same as java.exe for the purposes of running your Java program. jrew.exe works just like java.exe, too, but it doesn't spawn a new DOS window. Since the batch file references the jre.exe and classes.zip that we ship along with the app, there is never any chance of conflicts with any JDK version the user might have already installed. Also, we don't make the user manually install the JDK or muck about with path settings. And, this batch file will work no matter where the user decides to install our application's directory. This is the perfect solution for those of us who have to distribute our programs to computer illiterates! Hope this helps people! -Kip Fiebig www.kipley.com firstname.lastname@example.org
Credit where credit is due: Thanks for the info, Kip! It was exactly what I have been looking for. ------------------ ���
Bodie, You exactly right about the "jrew.exe"! Good job finding this info. Also, if you want to make a windows short-cut for you app and put it on your desktop, you can also use "javaw.exe". Try something like: <pre>%windir%\System32\javaw.exe -cp .;c:\someApplication\aJarFileNeededToRun.jar nameOfClassFileWhereMainIsLocated</pre> I also spent a lot of time on this bugger so please let me know if you have any more questions about it. Best Regards, Matt