Class GradApplet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----GradApplet
- public class GradApplet
- extends Applet
- implements Runnable
An applet that randomly draws colorful images on its workarea and
creates a Thread to animate the images. The mouseDown operation
enables to pause the thread activity
- Version:
- 1.1
- Author:
- Revathy Balaraman
-
GradApplet()
-
-
checkboundaries()
- Tests the x,y coordinates of the image that is to be displayed.
-
drawimage(Graphics, Color)
- Provides basic graphic methods to draw lines and fill ovals
-
init()
- Initializes the variables.
-
mouseDown(Event, int, int)
- The purpose of this method is to toggle between pausing and
resuming the thread’s execution.
-
pausethread(int)
- Causes the thread to sleep for the specified amount of time (msecs).
-
run()
- Provides the applet’s thread activity.
-
start()
- Checks the status of the thread.
-
stop()
- Stops the thread and waits for it to really die! In general, the
stop() causes a thread to leave its run() method and therefore end
its thread activity.
GradApplet
public GradApplet()
init
public void init()
- Initializes the variables.
- Overrides:
- init in class Applet
- See Also:
- init
start
public void start()
- Checks the status of the thread. If 'null', creates and starts the
thread. This process in turn invokes the run() method.
- Overrides:
- start in class Applet
- See Also:
- start
stop
public void stop()
- Stops the thread and waits for it to really die! In general, the
stop() causes a thread to leave its run() method and therefore end
its thread activity. It is accompanied by a join() call, which
forces the calling thread to wait until the thread is really dead.
- Overrides:
- stop in class Applet
- See Also:
- stop
mouseDown
public boolean mouseDown(Event ev,
int x,
int y)
- The purpose of this method is to toggle between pausing and
resuming the thread’s execution. The suspend() method suspends a
thread’s execution; when a thread is suspended it will not continue
its stream of execution until the complementary resume() method is
invoked. Suspending a thread is accompanied by clearing out the
applet’s drawing area (i.e. removing the previously drawn images)
through the repaint() method. This occurs because the applet does
not override the paint() method. The 'appRunning' variable is used
to keep track of whether the thread is suspended. Due to the action
performed by the mouseDown() method, the run() method gets repeatedly
started and stopped.
- Parameters:
- ev - Traps any mouse-click events
- x - The x coordinate of the mouseclick action/event
- y - The y coordinate of the mouseclick action/event
- Returns:
- true Returns true to indicate mouseclick action
- Overrides:
- mouseDown in class Component
- See Also:
- mouseDown
run
public void run()
- Provides the applet’s thread activity. The method defines just
what the thread is supposed to do when it is started. The thread
enters a loop, randomly drawing animated images on each iteration.
It runs until the applet is terminated or the thread is explicitly
stopped. The method also displays a string message at the lower
left side of the applet area.
- See Also:
- run
checkboundaries
public void checkboundaries()
- Tests the x,y coordinates of the image that is to be displayed.
If the randomly selected location is too close to the boundaries
of the workarea, the location is changed. This avoids partially
displayed images.
- See Also:
- checkboundaries
drawimage
public void drawimage(Graphics g,
Color c)
- Provides basic graphic methods to draw lines and fill ovals
- Parameters:
- g - The graphics object needed to draw the image
- c - The color selected to draw the image
- See Also:
- drawimage
pausethread
public void pausethread(int msecs)
- Causes the thread to sleep for the specified amount of time (msecs).
Thus, the GradApplet class uses the sleep() method to delay a
little between the image drawing process. The method also requires
catching Interrupted Exception objects. This is meant for situations
in which a thread has been interrupted by another thread.
- Parameters:
- msecs - Causes the thread to sleep for specific number of
milliseconds
- See Also:
- pausethread