Once you've created or opened a project, you can modify the source file(s) supplied with the project stationery to create your program. You may also want to add additional source files to the program or remove some of the ones that are already there.
WARNING: Although you can have multiple projects open at the same time, this is not encouraged, because it is extremely easy to get confused among the projects.
Java programs are built from a collection of classes. Each class should normally be stored in a file whose name is the class name followed by .java (e.g. class DrawPicture should be stored in file DrawPicture.java.
To create a new file, select File|New Text File, enter some Java code in the new window, then save the file with the appropriate name. Double-check to be sure you save it in the correct folder, which should usually be the one that contains the project file.
Before a Java file can be used as part of a program, it must be added to the project window --just creating a .java file isn't enough. You can add to the project files that you create or files containing Java code that you get from us or other sources.
Adding open windows. If the Java file is open in a CodeWarrior editor window, bring the window to the front, then select Project|Add Window.
Adding other files. To add other Java files to the project, either go to the desktop and drag the files into the project window, or else select Project|Add Files... . This brings up a dialog window, which you use to pick the files. Find the Java file(s) by moving to the correct folder(s) if necessary. Select the file name(s) in the top window and click Add. The selected file names should appear in the list at the bottom of the window.
You can select as many files from as many folders as you like. When you're finished, click Done to add them to the project.
The files in the project window can be arranged in any order you want. To move a file, drag it to the desired place.
Every Java application program begins execution in method main in one of its classes. Since every Java class can have a main method (often a good place to put code to test the class), one has to specify which main should be used to start the program. When you create a new Java project from stationery, this is done automatically. For example, the CUCSJavaApplication and CUCSJavaGraphicsApplication stationery begin execution in method main of class Application or GraphicsApplication respectively.
If you want to begin execution in another class (perhaps you've added one to the project or renamed the class used, e.g. CUCSApplication to Prog7), you MUST!! change the project settings to identify the class containing the appropriate main method. Click on the leftmost rectangular icon in the middle of the project window or select Edit|Settings.... (Note: The menu item will have some kind of project name in front of ``Settings'', e.g. Java Application Settings.) This opens the settings panel. Select Java Target in the list of options at the left of this window. Enter the name of the class --not the name of the file-- containing the desired main method in field Main Class:. Click Save, then close the window.
IMPORTANT: If the Main Class setting is wrong, CodeWarrior may exhibit very bizarre behavior when you try to run the program. If you're lucky, you'll get an error message complaining that some class you've never heard of can't be found.However, the Java Virtual Machine may begin executing whatever code it can find, strange windows may appear on the screen, or you may get error messages from Windows itself complaining about system-level issues that seem totally unrelated to your Java program. If you see such bizarre behavior, the Main Class: setting is one of the first places to look for trouble.
You can remove files from the project window if you no longer need them, e.g. to remove files included with the stationery (like Application.java or GraphicsApplication.java) when you want to substitute another class containing a different main method.
To remove a file, select the file name in the project window, then use one of the following techniques: (PC) hit the Delete key; (Mac) hit the Delete key or press Command-Delete; (PC only) right-click on the file name and select Delete from the resulting pop-up menu; (PC or Mac) select Project|Remove (this menu item doesn't always exist!).
You may want to change some of the other CodeWarrior settings for your project. You can change cosmetic things like the editor's font, text size, and keyword colors, as well as more substantive things like compiler options. Select Preferences... or Settings... from menu Edit to find out what's available. You can change things like the editor colors and fonts freely, but be careful about altering options you don't understand. Inappropriate changes can make it impossible to run your program.
One mysterious option that you might see on a PC is for all of CodeWarrior's windows to be inside a single ``master'' window. If this happens and you wish to turn it off, select Edit|Preferences. In the resulting IDE Preferences window, select the IDE Extras panel and uncheck ``Use Multiple Document Interface''.
Program (.java) files should be compatible across versions of CodeWarrior and be compatible between the Mac and PC, and project (.mcp) files should be compatible between the Mac and PC. However, CodeWarrior Pro 5 uses a new internal format for project files. While old project files can be updated --this might be somewhat tricky on the Mac-- to work with this release, new project files, including ones you get from us, will not work with previous versions of CodeWarrior. We suggest you upgrade to the current version, although you can create a new project file with an older version and add to it the source files you get from us.
Occasionally, usually after a particularly bad crash, a project file becomes damaged and CodeWarrior behaves strangely when using it. If the project file is badly damaged, CodeWarrior might crash when Run is selected --even before the program gets a chance to crash on its own-- or changes in the source program seem to have no effect on what happens when the program is executed. (But be sure this is not because you forgot to quit the Java runtime environment after your program finished.)
The first step when you suspect the project file is damaged is to force CodeWarrior to recreate some of the information in it. Select Project|Remove Object Code. This command causes CodeWarrior to discard the machine-language version of the program and some other information in the project file. This information will be recreated the next time you try to run the program.
If this doesn't solve the problem, the only solution may be to discard the damaged project file and use a new one. Get a new copy of the project file, if it was supplied as part of an assignment, or create a new project from stationery; add the program's other .java files to the project; check the Main Class: option; and delete from the project any stationery files you don't need.