CS 117 Lab: Outside BlueJ, and Applets

Lab 0: Create a Java program outside of BlueJ

Transform your "face drawing" program or some other non-email related Java program into a stand-alone Java program. Make some minor changes to it outside of BlueJ, recompile it, then wrap it up into a jar file with javabook.

Lab 1: Transform a program to an applet

1. Start up BlueJ. Open up a the BlueJ project corresponding to your favorite Java program. Remember that applets don't let you do file or terminal input/output, so choose a program that doesn't do these things (or take a program that does and remove them).

2. Add a new class to your project called MyApplet. Make sure to click on "Applet" when you create the class.

3. Copy the code from your "main" to the "init" method of the applet.

4. An applet will not correctly close your mainWindow, outputBox, etc. because your program never really "exits". It keeps on running within the web browser. Therefore, for each of your windows, you should call the "dispose" method at the very end of your program. For example, in one of my programs, I have code that looks like:

outputBox.waitUntilClose();
mainWindow.dispose();

5. Compile your program class and the applet

6. Copy the javabook folder (which you'll find in t:\javalibs) to your project folder. Make sure to copy the folder itself, not just the files inside.

7. Right click the applet, and choose "Run Applet". Choose "Run Applet in appletviewer" at the top (should be default), and click "OK". Your program should run as it usually does.

8. Change your program to not show your MainWindow, if you like.

9. Find the html and class files generated by BlueJ for your project. Copy them to your web directory as described at

        http://www.student.carleton.edu/builders/web_pages.html

10. Copy the javabook folder to your web directory as well.

11. Start up Netscape, try your webpage, and see if your applet runs!