Switching between console mode and graphical mode?

You can divide the project in two: the server and the GUI. You can run your server as a service (Windows) o daemon (Linux) and when you want the GUI, you have to launch and operate with it.

You can divide the project in two: the server and the GUI. You can run your server as a service (Windows) o daemon (Linux) and when you want the GUI, you have to launch and operate with it. It´s like applications as MlDonkey, Ettercap, etc.

You can use java.awt. GraphicsEnvironment.isHeadless() to check whether the environment where your program is running supports GUIs or not: public static void main(String args){ if (GraphicsEnvironment.isHeadless()){ // Run console mode } else { // Start in GUI mode } } If I were you, though, I'd make this a command-line switch so you can use the console mode in graphic environments, too. For maximum convenience, this would be a non-mandatory option which defaults to some kind of "auto" option, which uses the isHeadless check, like: public static void main(String args){ final List arguments = Arrays.

AsList(args); final int modeIndex = arguments. IndexOf("-mode"); final String mode = modeIndex == -1? "auto" : argument.

Get(modeIndex); if ("auto". Equals(mode)) runAuto(); else if ("console". Equals(mode)) runConsole(); else if ("gui".

Equals(mode)) runGui(); else System.err. Println("Bad mode: " + mode); } private static void runGui(){ ... } private static void runConsole(){ ... } private static void runAuto(){ if (GraphicsEnvironment.isHeadless()) runConsole(); else runGui(); } (TODO: Add error handling, remove magic string literals, etc. ) So, start your program with java YourMainClass or java YourMainClass -mode auto and it makes an educated guess whether you want GUI or console, use java YourMainClass -mode console to force console mode, or java YourMainClass -mode gui to force GUI mode.

You can pass parameters on the command line and examine them in main(String args). They'll end up in args. So the most simply way is to check for args.

Length > 0 && "-c". Equals (args0) to tell the program to run in console mode and to open a UI otherwise. Another option is to write two main() methods (in different classes) and use the right one.

In the program you can define commands to hide the GUI. Something like gui. SetVisible(false) should do the trick, it hides the window referenced by gui and all elements of it.

You could create a command line command that starts a GUI wizard that enables you to easily create the components/ configuration you want, and then enable the GUI to pass the complicated instruction back into your single application thread. Whether it is useful to have the GUI component destroyed after you have used it, or just hidden, is a decision you will have to make, regarding how often you will be using the GUI component.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions