University of Pittsburgh
  Spring 2004
CS0007:  Introduction to Computer Programming
Assignment 3: Pretty Picture (Applets)
DUE DATE
Wednesday, Feb 4, midnight
VALUE
20 points
BACKGROUND
pp. 53-54 JBD
FirstApplet.html
FIrstApplet.java

Have fun!

Objectives

In this project you will setup a simple applet then modify it.  This stands in contrast to the standalone programs we've written so far. You will also have a chance to look at the official Java documentation and use it to your advantage.

Setup

Rather than writing a program from scratch, in this assignment you will begin with a program provided by the book (FirstApplet.java), then modify it.  Here are the steps you need to take to get that applet up and running.  As usual, plug in your unixs id where you see "yourid":
  1. cd into your public directory (cd public)
  2. do an ls to see if you have an html directory (if not, make one by entering mkdir html)
    • (public/html is viewable on the internet)
  3. now cd back to your home (cd by itself)
  4. go to your java directory (cd private/java)
  5. copy the files from my public directory (cp ~hclane/public/java/applet/FirstApplet.* . )  (don't miss that last period)
  6. rename the java file to include your username (mv FirstApplet.java youridFirstApplet.java)
  7. edit youridFirstApplet.java and...
    • change the class name to include your userid
    • add a comment at the top with your full name
    • save the changes
  8. compile youridFirstApplet.java creating youridFirstApplet.class (javac youridFirstApplet.java)
  9. edit FirstApplet.html, find where it says FirstApplet.class and change it to begin with your userid (to match the class file name)
  10. copy FirstApplet.html to your html directory (cp FirstApplet.html ~/public/html)
  11. copy youridFirstApplet.class to your html directory (cp youridFirstApplet.class)
  12. open up a web browser (e.g., Netscape, Internet Explorer, etc.)
  13. go to:  www.pitt.edu/~yourid/FirstApplet.html
  14. If you have good karma, you should see a picture similar to what is on p. 54
A few notes about how to proceed:
  • Each time you make a change to youridFirstApplet.java, you will need to recompile it in your java directory (step 8) then copy it over to your html directory (step 11).
  • You do not need to copy your java file over (actually, you should not do this). 
  • After such a change, you may need to close your browser and start it up from scratch again (some of them do funky things with a cache).

What to do

Once you have this applet up and running, you should make some changes.  The applet uses two methods:  drawLine() and drawOval().  First, you should play around a bit with the coordinates given (the numbers given as arguments to these methods) and observe the changes.  Play around with them, draw a few extra lines or ovals.  Just get a feel for it.  Remember, you have to recompile and copy the new class over each time you want to view a change (up arrow on your keyboard will be very handy here).

Now it's your turn to explore.  Go to Sun's Graphics Java documentation and find the two methods you just used and read about them.  Look around at the other methods and find a few that require simple arguments (some are:  drawRect(), fillOval(), drawString() - the second one listed, and so on). 

Now go change your java code and put some calls in for these new methods.  Your final program should use at least two of these other methods (not including drawLine() and drawOval(), although feel free to use them as well).  You can draw a picture, make a fancy shape, or do whatever.  If you want to change the dimensions available to you, just edit FirstApplet.java.

Handing your work in

Make sure you have put your full name in as a comment at the top of your java code and that your userid is included in the class and file names (this is VERY important!).
  • Copy your java source file to the handin directory (use assignment3 as the directory name)
  • Make sure you use FirstApplet.html as the class loader file in your html directory (that's where the grader will look to run your code).
See assignment 1 or the handing your code in handout to remind you of the steps.  Don't forget to verify the handin using ls.

Suggestions/Hints

If you want to play around with colors, you can call g.setColor(Color.blue) for blue, or plug in any other basic color.  See the documentation for your choices.  This is optional, of course.

Last Updated:1/29/04 by H. Chad Lane