CodeWarrior uses what is called an integrated desktop environment (IDE) to conveniently perform both editing and compiling (and other tasks). More precisely, the CodeWarrior IDE provides a text editor window in which you can enter the text of a program, and then save that program in a file. Once your program is saved, you can translate it into byte-code using the CodeWarrior compiler and linker.
To get started, invoke CodeWarrior according to your instructor's directions. (This may involve double-clicking on an icon on your computer's desktop, or clicking on the Apple menu and choosing CodeWarrior from that menu.) The only change should be that the rightmost menus at the top of your screen will be replaced by menus specific to CodeWarrior.
Our first program will input an integer and display twice that value, four times that value and then 8 times that value. We will thus name the executable program Mult, and name the source program Mult.java (Java source programs end in .java by convention.)
The CodeWarrior IDE provides a convenient feature called a project that simplifies the translation of a source program into machine language. The normal procedure is to create such a project first, before we create any source files for our program, (though it is quite easy to add existing source files to a project.)
To create a project, move the mouse to the File menu and choose New ... from the menu. This should cause a dialog window named New to appear, containing a three tabs labeled Project, File, and Object. Make sure the Project tab is selected. We have a number of choices for the kind of project we will create. You should see Java Stationary in your list of choices. Click on it so that it is highlighted. We have just chosen the kind of project we will be making.
Code Warrior will create a folder for us which will contain the project. We must let Code Warrior know where to put this folder. The box labeled location serves this purpose. Follow your teachers instructions as to the appropriate location to place your project.
We must give our project a name. There is a box labeled Project name, click inside the box and then type in Mult.mcp. The standard extension for a Code Warrior project is mcp.
When you are done, click on OK.
You should now see a window titled New Project. You should see the choices : Java 2 and JDK 1.1. These are different version of Java that you can use. Lets choose the more recent Java 2 by clicking on the triangle next to it. We now have choice for whether we want to build a Applet, Application, or a Library. Today we will choose Application by clicking on it so that it is highlighted. Then click OK to finish.
We have chosen the kind of project we are making. Most of the exercises in this manual will use this same kind of project. Since you will need to repeat these steps in each subsequent exercise, try and commit them to memory now.
Code Warrior provides a Java Applet Wizard and a Java Application Wizard. If you create a project of these types, you will have the ability to design a graphical user interface (GUI) and have some code generated automatically. In the GUI sections of this manual, we will hand code our GUI to get familiar with how Java implements its components. Once you have gained some familiarity, you are encouraged to use the wizards.
If you have succeeded, you should now have a folder which will hold all the project files. Inside this directory will be a project file with the name Mult.mcp, a java source file named TrivialApplication.java, and a folder named Mult Data. You should also see a project window named Mult.mcp with tabs for Files, Segments and Targets. This is your window into the project and it will allow you easy access to the pieces of your project. If you click on the triangle next to sources, you should see that TrivialApplication.java is a part of your project. As it currently is, this project will compile and create an application that will print "Hello World". If you double click on TrivialApplication.java you can see the source code for this program.
We could just use the file TrivialApplication.java as a basis for the code we are going to write, but instead we will create a new source file and make it part of our project.
Lets create a new file named Mult.java in which to store our program. To do so, move the mouse to the File menu within the and choose File -> New Text File. A blank window will appear, named untitled. To give it the proper name, choose File -> Save and in the dialog box that appears, replace untitled with Mult.java. Make sure that it is being saved in the Mult folder by verifying that Mult appears in the box in the upper left hand corner. If not, you can navigate up the directory hierarchy by clicking on the box and then selecting a folder. To go down the hierarchy, double click on a folder listed in the scroll box. When you are in the right place, click on the Save button. The window will then be renamed Mult.java. Then choose Project -> Add Window and Mult.java will be added to your project.
Our project will require the ann.easyio package to run. The first thing for you to do is to place a copy of the ann folder in your project folder. (This step is not strictly necessary, but is often done.) Remember that you can use option while dragging the ann folder to make a copy. Even though the code is now inside our project folder, the compiler needs to know the access paths (what directories to look in.) The easiest way to do this is to click and drag the ann folder in Mult and drop it on the Mult.mcp window. Code Warrior will then do the needed things. (This step does change the location of the ann folder.)
One final bit of housekeeping and then we will be ready to begin on the program. Return to Mult.mcp, the project window. (If it is hidden by Mult.java, you can use Window -> Mult.mcp to make it the active window and bring it into view.) In that window, click the right-arrow labeled Sources. Lets get rid of the TrivialApplication.java file. Click on TrivialApplication.java and hold the mouse button down. A mini-menu will appear from which you can choose Clear. Do so and TrivialApplication.java will be removed from your project. This does delete the file. It is still in the project folder, but will not be compiled.
Unfortunately, Java still believes that TrivialApplication is the class that holds our program. We need to change it to Mult. Use Edit -> Java Application Settings to bring up the window with all the settings for this project. Do not make random changes here or you may regret it. Click on Java Target under Target. ( You may need to click the triangle to see the Target possibilities). Change the Main Class from TrivialApplication to Mult. Click on Save.
While we are here, there is one more thing to check. Under the Linker setting click on Java MacOS Settings. We need to make sure that the input and output both go to the message window. In the right hand side of the window find Additional Settings. Click so that you see Redirect stdin/stdout next to it. Next to redirect stdout: you should see Message Window. Next to redirect stdin: you should see Message Window. If that is not the case, click to change it.
Click on the settings window's close box to make it go away.
Back to the Lab
Back to the Table of Contents
Back to the Introduction