Class Bouncer
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----Bouncer
- public class Bouncer
- extends Applet
- implements Runnable
Controlling class to simulate a ball bouncing
-
ball
-
-
Bouncer()
-
-
getDimension()
- Accessor function just returns the width and height as a
Dimension
-
getHeight()
- Accessor function just returns the height of the applet
-
getWidth()
- Accessor function just returns the width of the applet
-
init()
- Initialize the application.
-
main(String[])
- main just builds our Bouncer applet, and displays the
applet in a frame that we resize to be the size of the
bouncer applet, then starts the applet.
-
mouseDown(Event, int, int)
- Called when the mouse goes down.
Deprecated.
-
mouseDrag(Event, int, int)
- Reset the ball to this position as the user drags it around.
Deprecated.
-
mouseUp(Event, int, int)
- Called when the mouse goes up.
Deprecated.
-
paint(Graphics)
- Draw the scene
-
run()
- Keep the ball(s) moving
-
start()
- Create a thread and make this thread's target the applet.
-
stop()
- Stop the ball from moving
ball
public Ball ball
Bouncer
public Bouncer()
init
public void init()
- Initialize the application.
- Overrides:
- init in class Applet
start
public void start()
- Create a thread and make this thread's target the applet.
- Overrides:
- start in class Applet
run
public void run()
- Keep the ball(s) moving
stop
public void stop()
- Stop the ball from moving
- Overrides:
- stop in class Applet
paint
public void paint(Graphics g)
- Draw the scene
- Overrides:
- paint in class Container
getWidth
public int getWidth()
- Accessor function just returns the width of the applet
getHeight
public int getHeight()
- Accessor function just returns the height of the applet
getDimension
public Dimension getDimension()
- Accessor function just returns the width and height as a
Dimension
mouseDrag
public boolean mouseDrag(Event e,
int x,
int y)
- Note: mouseDrag() is deprecated.
- Reset the ball to this position as the user drags it around.
- Overrides:
- mouseDrag in class Component
mouseDown
public boolean mouseDown(Event e,
int x,
int y)
- Note: mouseDown() is deprecated.
- Called when the mouse goes down. Stop moving
- Overrides:
- mouseDown in class Component
mouseUp
public boolean mouseUp(Event e,
int x,
int y)
- Note: mouseUp() is deprecated.
- Called when the mouse goes up. Start moving again.
- Overrides:
- mouseUp in class Component
main
public static void main(String args[])
- main just builds our Bouncer applet, and displays the
applet in a frame that we resize to be the size of the
bouncer applet, then starts the applet.
By providing this main method, we can invoke the applet
by simply running "java Bouncer" (when Bouncer.class is in
our $CLASSPATH). Without this main method, we'd have to use
"appletviewer Bouncer.html" to run the applet.
Bouncer.html: