Java Applets: Interactive Programming

Lab/Assignments


The purpose of this assignment is


Instructions:

Google has a fun way of displaying their logo a bit dressed up on holidays of some sort. For example:

On Google's birthday
Olympics in Athens
Father's Day
Leap Year

You need to write a Java program that produces a GUI where the applet is different based on the time of day.
You'll need to create three classes each that extend JPanel.


In each one, draw inside the paintComponent method (like the Smiley example from the textbook). This is to be the *background* of your applet.
Inside your applet class, figure out the hour of the day using the Calendar class like you did in lab with the Weather example.
The Calendar class is from the java.util package, so we also need an additional import statement at the top of our program.
        import java.util.*;
To use the Calendar class, we can get the current time by calling getInstance:
     Calendar rightNow;
     rightNow = Calendar.getInstance( );
To get the current hour from our Calendar instance, we call:
        int hour;
        hour = rightNow.get( Calendar.HOUR_OF_DAY );

In your applet class you should determine which hour of the day it is. Then use either an if-else structure or a switch statement to determine which helper class to instantiate.
Then add a JLabel with appropriate text to the center of the panel.
HINT: You should use BorderLayout for the applet and add either the Morning, Day or Evening class to the applet only.
You should then add one JLabel to either the Morning, Day or Evening class that is centered. You will need to refer back to chapter 5 on how to align the label centered horizontally.

When the hour is one of the morning hours, your applet should appear as:


When the hour is one of the day hours, your applet should appear as:


When the hour is one of the evening hours, your applet should appear as:

Specifications


What To Electronically Submit:

Using the WebCT Assignment Submission System, submit:

Click Here for how to use the RamCT Submission System.


Copyright © 2006-2009: E.S.Boese All rights reserved.