Java Applets: Interactive Programming
- The purpose of this assignment is
- extend the JPanel class
- practice if/else or switch statements
Google has a fun way of displaying their logo a bit dressed
up on holidays of some sort.
|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.
- morning is from 1am to 11am
- day is from noon to 5pm
- evening is from 6pm to midnight
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.
To use the Calendar class, we can get the current time by calling getInstance:
rightNow = Calendar.getInstance( );
To get the current hour from our Calendar instance, we call:
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
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:
- The program should be set to run at 500 pixels wide and 300 pixels high.
- The backgrounds MUST each be a separate class named exactly
Morning, Day and Evening that each extends the JPanel class.
- The JLabel must have text larger than 16 pt font, be a different color
than black, must be centered horizontally on the applet, must have at least
2 lines of text and the text must be centered. You must have text that
- You may change the backgrounds. You may draw anything you like in
each paintComponent method inside the classes that extend JPanel.
- You may change the text so long as it is obvious that you were able
to get the text centered (e.g. you may not have 3 lines of text that
align to the same width).
- The text must be easy to read, so the background should not flush out the foreground.
- If designs are really well done, extra credit will be available
through either my discretion or another class competition.
- When you are satisfied that your GUI compiles and runs correctly,
submit the Homepage.java, Morning.java, Day.java and Evening.java
and all images (if you use any) files through the RamCT
Assignment Submission page, as described below, and on the CS Help Documents page.
What To Electronically Submit:
Using the WebCT Assignment Submission System, submit:
- the Java GUI program file, Homepage.java
and the classes
Homepage.java, Morning.java, Day.java and Evening.java
Make SURE you name it correctly!!
- ALL image files necessary to run your program!!
for how to use the RamCT Submission System.
Copyright © 2006-2009: E.S.Boese All rights reserved.