Lab 02: Random Fortune 

Goal: Display a random fortune from a list of 5 choices with a picture to convey a positive or negative fortune.

smile.gif frown.gif BEFORE your program will run, you need to save these pictures into the same folder as your project or .java files.

Create DriverFortune and PanelFortune using the starter code. Add your code to PanelFortune. 


    1. Create 2 labels: one for the words, one for the picture
      (both are JLabels)
    1. Display a message on the words label: "Find your fortune" 
    2. Display a picture of a smile on the picture label
    3. Create a button that says "Click here" 
    1. When the button is clicked: 
    2. Choose a random number from 0 to 5. 
    3. If the number <1 display fortune 1 on the label
    4. If the number is between 1 and 2, display fortune 2 
    5. … Etc. 
    6. If the forutne is good, display the smile
    7. otherwise, display the frown

How To:

/*1 create a button, attach a listener and add the button to the panel */ 

(see your Random number program if you need help) 

/*2 create a label for the picture and add it to the panel */ 

  picture = new JLabel(); 
  picture.setIcon(new ImageIcon("Smile.gif")); 

/*3 generate a random number from 0 to 5 and show the matching fortune. Show a smile if good or frown if not */