Now that you are familiar with your Java
programming environment, we can shift our attention to understanding
and using the Java language to describe and solve problems. That, after
all, is the real focus of this course.
In this
and all subsequent labs, the sample
lablets are provided for you on these lab pages so that you can begin the exercises
immediately without having to type any lengthy programs. The Chapter 2
lablet is a class that uses a few of Java's built-in libraries
to do some graphic manipulation, somewhat like we did in Chapter 1.
In this chapter, though, we'll use the lablet to investigate the basic
structure and syntax of Java programs.
![]() |
In this lab, you will: | ||
![]() |
Run the Chapter 2
lablet, |
||
![]() |
Inspect the lablet's code, to gain some understanding about how a Java program is written. |
||
![]() |
Experiment with some of the features of a program, by modifying the lablet and interpreting the results of your changes. |
||
![]() |
Continue learning about programming by modifying and extending the lablet--on your own--to produce new and different behavior. |
Date
class to retrieve the current time,
as follows:Date myTime = new Date(); int myHour = myTime.getHours(); int myMinute = myTime.getMinutes(); int mySecond = myTime.getSeconds();Since your applet won't do any event handling, you won't need an
actionPerformed()
method and so you should also remove
the phrase implements ActionListener
from the class header.
In fact, since you won't have a button to add to the applet, you won't
even need an init()
method--the only method your applet will need
will be paint()
. Look at the sample applet on pp. 42-43 for
an idea of what you'll write.Graphics
class, and you'll
see that it provides methods for drawing a number of common shapes.