Fundamental Programming Concepts
Summer 2000

Lab 10

Overview

This lab requires the use of:

  • Applets
  • Graphics
  • Events/listeners
  • Components

 

Preliminary: Creating Applets in Metrowerks
  • Create the project as normal, except:
    • When choosing the Project Stationery, choose Java Applet instead of Java Application.
    • You won't specify a main class to run under Java Applet Settings, because applets don't use main methods. Instead, do the next step:
    • Under Edit->Java Applet Settings->Linker->Java Output, make sure that the output type is set to "Class Folder" and that there is nothing in the "Name" text box (in particular, if "Java Classes" is in the textbox, delete it).
  • Delete TrivialApplet.java and TrivialApplet.html from your project.
  • Create a .java file for the project just as you always have.
  • Create a .html file for the project, adding it just as you would the .java file. You need to put at least the minimal HTML in the file as discussed in lecture.

 

Part I: Poem

Create an applet that displays a poem and a picture that relates to the poem. 

The poem may be lines from an actual poem, song, a quote, lines from a book, or any other text (e.g., it need not actually be a poem -- but do please name your class Poem anyway). The poem must be displayed using at least 3 lines of text. 

The picture should be created using at least four different methods from the Graphics class. Also, it should use at least 2 colors other than black and white. Don't be concerned about the artistic merit of your picture -- Java's drawing methods aren't terribly sophisticated.  Don't steal the pictures from your text (snowmen and stick figures are right out).

 

Part II: SlotMachine
Create an applet that simulates a simple slot machine. Three numbers between 0 and 9 should be randomly selected and then displayed in three different Labels. Provide a Button that, when clicked, changes the numbers (i.e., simulates pulling the handle on the machine). If all three numbers come up the same, the user should be rewarded with a message in a fourth Label. If two numbers are the same, the user should be told that s/he is close, and to try again. Otherwise, the label should display a message encouraging the user to try again. There is no need to keep track of money won or lost.

 

Submitting

Submit exactly the following:

  • Lab10
    • Poem.java
    • Poem.html
    • SlotMachine.java
    • SlotMachine.html