-3

I'm trying to make a program that can run with a gui or in a terminal only mode with no gui. How could I make it so that when the program is called in the terminal, the user adds an argument to determine whether to run with a gui or not?

By entering something like this when they start my program: java myprogram -Nogui

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
N.LeFevre
  • 19
  • 6

1 Answers1

1

In the main method of your java program, just check if any of the arguments passed (the String[] parameter) are the one you are looking for.

public static void main(String[] args) {
    boolean useGui = true;
    for(String arg : args) if(arg.equals("-Nogui") useGui = false;
    // Now check `useGui` to see if a GUI should be displayed or not
}
SamTebbs33
  • 5,507
  • 3
  • 22
  • 44