lab 15 5 5

background image

Lab 15.5.5 Digital Clock


Estimated Time: 40 minutes

Learning Objective:

• In this lab activity, the student will create an applet that will display a digital clock with hour, minute,

and second.

Description/Scenario:

• Create an applet that displays a digital clock

• Display hour, minute, and second

• Use the Thread sleep method to repaint the clock every second

• Have the clock update the time every second using a Thread


File Management:

Open BlueJ. Click on Project from the BlueJ main menu and select New. In the New Project
window and in the Look in: list box select c:\. Now, double click the javacourse folder listed in
the text window and a different New Project window opens with javacourse in the Look in: list
box. Now, double click the chap15 folder listed in the text window and a different New Project
window opens with chap15 in the Look in: list box. Type lab15.5.5 in the File name text box
and click on Create to create a lab15.5.5 subfolder in the chap15 folder.


Tasks:

Step 1 Creat DigitalClock class

a. Create a class named DigitalClock that extends Applet and implements

Runnable.

b. In

the

init() method, create the Thread and start the Thread.

c. Use

the

run() method to call the Thread sleep() method and the repaint() method to

repaint the clock every second.

d. Use this code to get the current hour, minute, and second:

Date myHours = new Date();
Date mySeconds = new Date();
Date myMinutes = new Date();
hrs = myHours.getHours();
sec = mySeconds.getSeconds();
mins = myMinutes.getMinutes(); //Note: these methods are deprecated but work.


Step 2 Run Applet

a. Run the applet in the appletviewer provided by BlueJ.

1 - 1

Fundamentals of Java Programming Lab 15.5.5

Copyright

 2003, Cisco Systems, Inc.


Wyszukiwarka

Podobne podstrony:
Pomiar wilgotności względnej powietrza przechowalnictwo lab 15
W2K3-15-raport, WAT, SEMESTR VII, Systemy operacyjne windows, Systemy operacyjne windows, sow, W2K3-
Lab 8, 15 - rdzenie wiertnicze, SKAŁY15, Nr ˙wiczenia
lab 15
Lab 15, Notatki, FIZYKA, SEMESTR II, laborki, lab
LAB 15 OPIS I WNIOSKI, sgsp, Hydromechanika, HYDROMECHANIKA 1
lab 15 5 2
lab, Lab 15, WOJSKOWA AKADEMIA TECHNICZNA
okładka-sb lab 15, Chemia Fizyczna, chemia fizyczna- laborki rozne, Rozne
IE RS lab 15 diagram
lab 15 3 2
Lab 15 id 257443 Nieznany
IE RS lab 15 overview
Zamrażanie owiewowe przecho lab 15
lab. 15 - baron, Chemia fizyczna AGH laborki, lab 15
Pomiar wilgotności względnej powietrza przechowalnictwo lab 15
W2K3-15-raport, WAT, SEMESTR VII, Systemy operacyjne windows, Systemy operacyjne windows, sow, W2K3-
Lab 15 tez kurwa

więcej podobnych podstron