Using Code Warrior with applets

REcall that there are two kinds of Java programs: applications and applets. Applets are intended for use in web pages, and therefore are invoked from a .html. It is possible for a project to have several applets, each with its own .html file. Some of the things about running applets are similar to running applications, but some are different. Please read below about how to run applets.

An aplet project consists of the project file, one or more Java files, and one or more HTML files. You will be able to identify the project files by the .mcp extension (stands for Metroworks CodeWarrior Project) and the Code Warrior project file icon shown below.

Note the difference from a .java file icon below:

Using Code Warrior

  1. Open up the folder where your files are. Find the Code Warrior project (i.e. .mcp) file and double-click it to open it up. Do NOT open (by double-clicking) the .java files directly!

  2. The project file window appears. You must keep this window open while working on your programs. You can resize the window by pulling on its down right corner.

    Note that the window has 3 tabs: Files, which shows you the files included in the project, Link Order, which allows you to specify the order of compilation of your files, and Targets. For the first few weeks you will only be using Files.

  3. Double-click on the name of the file to open it. You can then edit the file. Note that Code Warrior uses different colors for different elements of your program: blue for Java keywords, light blue for variable names and methods, red for comments, and black for everything else.

    If you have changed a file, you can tell that it has been changed by looking at the project file window. A red check mark appears after files which need to be brought up to date.

  4. Be sure to save your files often! (Apple-S)

  5. In order to see how your program works, you need to compile, link, and run it. There are two ways of doing it:
    Helpful Tip: if you press the Run icon or choose Run from the menu, the program is automatically recompiled and re-linked, so usually it is enough just to use c. It also automatically saves all files that have been changed (before recompiling the program). So in most cases Run is the only option you need to use when changing your program.
  6. If your program does not have errors, choosing Run will start Apple Applet Runner and intialize the applet:

  7. If you are running a BuggleWorld program, pressing the Run button on the applet will execute your code:

    You can also use Reset button to clear, and Step button to run the code step-by-step.

  8. Your program may be performing some printing, or it may encounter an error during execution, for instance, a buggle may be facing a wall and trying to move forward, as on the picture below:

    All printing of your program and all messages about errors during execution are printed to a console window whichj pops up when the first printing or error message needs to be displayed:

  9. If you want to change something in your program, close the applet by clicking on the small square in its left top corner (just as you normally close windows on a Mac), then change and recompile your program, as shown above.
    Note: The console for the new run of your program will keep all the messages from the previous run.
  10. If there is a mistake in your code, Code Warrior will pop up an error window. Below the error message you see the line of code where the error is.

    Correct the error:

    Then re-make your program as shown in the previous step. It is a good idea to just fix one error at a time and then try to re-make your code again.

  11. When you are finished, please don't forget to quit Code Warrior! (Apple-Q)

    If the Apple Applet Runner is running, select it from the active applications (the icon in the upper right corner of your machine). Then choose Quit from the File menu.