Using CodeWarrior
Creating a HelloWorld.java program
This example is intended to get you started with CodeWarrior. This
example assumes that you are working from CDF-PC on campus; if you
are working from home, you'll probably want to use C: instead of H:
for the hard drive. The instructions for invoking CodeWarrior at home
may be different if you're using a different version of CodeWarrior.
This document contains details about how to create a Java program from
scratch, or how you can include existing Java files (files that have
already been created and exist on your hard drive - you may have
downloaded these from the course web site). All steps are the
same for these two tasks, except for step 4. Step 4 (a) explains how
to create a new Java program, and step 4 (b) explains how to include
existing Java program files. In this example, we assume that the Java
program will be contained in a single Java file called
HelloWorld.java. We will also name our project HelloWorld.
If you are working on take-home quiz 2, you might also find the
Quiz 2 CodeWarrior Tutorial helpful.
- Invoke CodeWarrior
- If working from CDF-PC, double click on the "Applications" folder
which will be showing on your desktop, and then double click on the
"CodeWarrior" icon.
- If working from home, select Start -> Programs -> CodeWarrior Pro 5
-> CodeWarrior IDE
- Create a new project
- To open a new project, select File -> New...
- Click on Java Stationary
- Project name: HelloWorld
(We are using the name of the class containing the main method.
Alternatively, we could use the name of the folder where
your files are stored.)
- Location: H:\java\HelloWorld
(Choose a folder/directory that you have write permission on.
Your files for this program will go here. If the "java" folder
does not already exist in your H: drive, you will need to click
on "Set...". This will bring up a "Create New Project..."
window. Change "save in:" to H: and then click on the yellow
Create New Folder icon and type in "java" and then click "Open"
and then click "Save."), and then click OK.
[Notice that whatever name you choose for Project name will
always be the last part of your Location.]
[Note that we could have simply used a Location name of
H:\HelloWorld. Having the "java" directory, however, helps to
organize things better on your harddrive. This is especially
helpful if you are working from home and have several other
folders already on your hard drive.]
- Click on the "+" next to Java2 to open it up, and then select
Java Application (or you may find the Csc 1.1
stationary works better if you're working from CDF-PC), and click
on OK. This will bring up a HelloWorld.mcp window.
- Tell Java where the main method is
- Select Edit -> Java Application Settings... (or you could click
on the icon for this in your mcp window)
- Click on Java Target (under the Target settings)
- Main Class: HelloWorld
(change this to the name of your class containing the main
method).
- Click on Save, and then close the window by clicking the "x"
in the top right corner of the window.
- Include Files - create or open Java files
- Click on Sources in the HelloWorld.mcp window to highlight it.
This ensures that the file you add or create will be put into the
Sources folder.
- (a) Create new Java file
- (b) Add existing Java file
- If the file that you want to include in your project is on
the course web site, at this point you would click on this file
from the course web site and then save it in your H:\java\HelloWorld
directory.
- If the file that you want to include in your project is in
some other directory on your computer, you can use Windows
Explorer to move the files into the H:\java\HelloWorld directory
at this point. More details about using Explorer are provided in
the section at the end of this document.
- For both part (a) and (b)...
With Sources still highlighted, click Project -> Add Files... and
select the HelloWorld.java file in the H:\java\HelloWorld directory.
(If desired, more than one file could be selected by holding the CTRL
key and left clicking each file).
- The HelloWorld.java file will automatically be added to Sources
in your HelloWorld.mcp window. If you don't see it there, click on
the various tabs in this window (Files, Link Order, Targets) to cause
it to refresh. [This seems to be a CodeWarrior bug.]
- Click on the "+" next to Sources, and you will see the files that
are part of this program. Double click on your ".java" file to bring
up a window that will allow you to view or edit it.
- If you used the Java Application stationary in step 2 above,
you will have a file called TrivialApplication.java in your Sources
folder. This file is created automatically by the Java Application
stationary, and can be deleted. Click once on TrivialApplication.java
to highlight it, and then press the Delete key on your keyboard, and
then click on OK.
- Compile
- Select Project -> Make (or the Make icon). Any compile errors
will come up at this time. They will indicate the line number that
has a problem.
- Run
- Select Project -> Run (or the Run green arrow icon). The output
will come up in an MS-DOS window. Any input for the program would be
entered here. Press Enter in this window when the program has
finished.
- Closing CodeWarrior
- Select File-> Exit to leave CodeWarrior. Your project will be saved.
- Reopening a Project
- Suppose you want to modify the HelloWorld project the next time
you use CodeWarrior. You would start up CodeWarrior as outlined in
step 1, and then you would select File -> Open... An Open window will
pop up. You will change the directory in this window until you get to
H:\java\HelloWorld, and then you will open the HelloWorld.mcp file.
It stores all the information about your project.
- Another way of reopening a project is to locate the project's
HelloWorld.mcp file from within Explorer (or by double clicking on
My Computer, H: drive, java, and then HelloWorld.mcp), and then you
can double click on it. This will start up CodeWarrior, and take you
right into that project. Note that since there are two types of
HelloWorld files in the directory, you might have to select View ->
Details in Explorer to determine which is the CodeWarrior Project file
that you want to open.
Using Windows Explorer
In step 4 (b) it talks about using Windows Explorer to copy files
from one directory to another on your computer. It should be
noted that this application is not part of CodeWarrior. You
can minimize your CodeWarrior application (by clicking on the minus
sign at the top right corner of CodeWarrior), and then start up
and run a Windows Explorer session as follows:
Invoke Explorer
- Right click on Start -> Explore
The environment
- On the left side of the window you can click to open up drives
(such as A: or H:), and folders (indicated by a yellow icon.
- On the right side it will always show the files and folders
that are in the folder that has been selected (by double
clicking) in the right side of the window.
Create a New Folder
- Suppose you wanted to create a folder called H:\java
where you could store all your Java Projects. This could be
done from within CodeWarrior, as explained above, or you could
do it right here in Explorer.
- On the left side of the Explorer window, you would double click
on H: to open the H: drive.
- Then you would select File -> New -> Folder from the
menu, and type in java for the filename.
Copying files
- Suppose you wanted to copy the AssignmentZero.java file from your
H:\Download\ folder into your
H:\java\AssignmentZero folder.
- On the left side of your Explorer window you would double
click on H:, and then double click on Download. At this point,
you will see AssignmentZero.java on the right side of the Explorer
window.
- Single click on AssignmentZero.java which is showing
on the right side of the window. Then select Edit -> Copy.
- Now on the left side of your Explorer window you will change
the folder to the folder where you want to place this file.
Double click on H:, then double click on java, and then double
click on AssignmentZero. Then select Edit -> Paste, and
the file will appear in this folder.
- Now you can close Explorer (click on the "x" in the top right
corner) and go back to CodeWarrior and you can then bring this
file into your CodeWarrior project. If you minimized CodeWarrior
before starting up Explorer, you can bring it back to full size
by clicking on "Metrowerks CodeWarrior" which will be showing
along the bottom of your screen.
© Copyright 2001 Andria Hunter.