tut07 - EE3206/EE5805 Java Programming Application Tutorial...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 EE3206/EE5805 Java Programming & Application Tutorial 7 – Displaying a Clock In this tutorial, you are going to experience the drawing ability of Java AWT/Swing API. You are required to write a GUI application to display a still clock as shown below. The interface consists of three components: a frame ( DisplayClock ), a clock panel ( StillClock ) and a text panel ( MessagePanel ). The corresponding class skeletons are given to you. In order to display the time properly, you have to provide the full implementation for the following method protected void paintComponent(Graphics g); in the StillClock class. You need to draw 4 parts: 1. clock boundary and marks (the circle) 2. second hand ( θ =second x 2 π /60) 3. minute hand ( θ =(minute + second/60) x 2 π /60) 4. hour hand ( θ =(hour + minute/60 + second/3600) x 2 π /12) Finally, write another class DisplayRunnableClock by modifying DisplayClock . You may need to use Thread to allow animating the clock.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 The class “DisplayClock” import java.awt.*; import javax.swing.*; public class DisplayClock extends JFrame { public DisplayClock() { // Create an analog clock for the current time StillClock clock = new StillClock(); // Display hour, minute, and hour in the message panel MessagePanel messagePanel = new MessagePanel(clock.getHour() + ":" + clock.getMinute() + ":" + clock.getSecond()); messagePanel .setCentered(true); messagePanel.setForeground(Color.blue); messagePanel .setFont(new Font("Courie", Font.BOLD, 16));
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course EE 3206 taught by Professor Cwting during the Spring '07 term at City University of Hong Kong.

Page1 / 5

tut07 - EE3206/EE5805 Java Programming Application Tutorial...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online