Class MyCanvas2
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----MyCanvas2
- public class MyCanvas2
- extends Canvas
- implements ScrollReadable
To use the Scroller, a Canvas must be subclassed, and the subclass must implement the ScrollReadable interface.
-
MyCanvas2()
-
-
paint(Graphics)
- The paint method creates and paints to the offscreen image.
-
scrollDown()
- This method draws the offscreen image on the canvas using the x, y positions which creates the scrolling effect.
-
ScrollRead(float, float)
- This method is called from the Scroller whenever the scrollbars are used, and
changes the x/y positions of the offscreen image relative to the canvas for the
offscreen image to scroll.
-
update(Graphics)
-
MyCanvas2
public MyCanvas2()
paint
public void paint(Graphics g)
- The paint method creates and paints to the offscreen image.
- Overrides:
- paint in class Canvas
scrollDown
public void scrollDown()
- This method draws the offscreen image on the canvas using the x, y positions which creates the scrolling effect.
update
public void update(Graphics g)
- Overrides:
- update in class Component
ScrollRead
public void ScrollRead(float hpercentage,
float vpercentage)
- This method is called from the Scroller whenever the scrollbars are used, and
changes the x/y positions of the offscreen image relative to the canvas for the
offscreen image to scroll. The width and height of the offscreen image is multiplied
by the horiontal and vertical percentage (a float between 0 and 1)passed from the
Scroller. The results are multiplied by -1 for the x and y position of the offscreen
image.
For example, if the vertical scrollbar is scrolled down 10%, then .10 is passed to this
method in the vpercentage variable. To scroll the image 10% "upward", 10% of the offscreen
image must be drawn above and out of view of the canvas allowing the rest of the 90% of
the offecreen image to be viewed. To calculate the 10% that must be out of view, multiply
the offscreen images height by .10, the result of this times -1 is where the y position
of the offscreen image must start relative to the canvas.