Command Line Arguments and jGrasp

Background

What is a command line argument, you ask? Well, back in the good old days, before graphical user interfaces existed, one communicated with a computer via a command line interface. (Probably no one called it that until after at least one other kind of interface surfaced. The second kind was probably the menu-driven interface. Only later did GUI's (i.e., graphical user interfaces) appear.)

In a command line interface, the computer (via its operating system's "shell") simply gives you a prompt and waits for you to type in a command, which it then performs. For example, in Unix the more command displays the contents of a specified file. Hence, after instructing the machine to display the contents of junk.txt (but before it responds), on the screen you will see (assuming that the prompt is a percent sign, which is commonly used)

% more junk.txt

This line of text is a command line. The first item on the line is the name of the command; the remaining items are the arguments to be passed to that command. (A command is analogous to a method in Java.) In this example, there is only one argument, junk.txt.

To run a Java program, say KeyPadLockDriver, via a command line interface (such as that provided under Windows by the Command Prompt application, which simulates the old MS-DOS shell), you would type in something like

java KeyPadLockDriver 34567

This invokes the java command, which runs the Java program indicated by the first argument. (Specifically, it invokes the main() method in the corresponding class.) Subsequent command line arguments are passed to main() via its args parameter, which is an array of type String[], one argument per array element.

However, you would probably prefer to run Java programs from inside jGrasp (rather than from a Command Prompt window). Is it possible to do this for a class whose main() method expects arguments to be passed to it? Yes!

Using Command-Line/Run Arguments in jGrasp

Here's how. On the menu bar of jGrasp, left click on Build. A drop-down menu should appear. Click on the Run Arguments check box (so that a check mark appears in it). This should cause a new text box, labeled Run Arguments, to appear just above the box containing code. Into that box enter whatever arguments you want. It is understood that the arguments are separated by spaces. Then run the program (by clicking on the run icon in the usual way).