Class misc.ScrollableCanvas
public class ScrollableCanvas extends Panel {}
This is the main class that adds Scrollbars to the Canvas Mycanvas
which is defined in the same file. The design of this class was inspired
by an example in Sun's Java Tutorial.
Let me first define Myclass.
Here's how misc.ScrollableCanvas is defined..
This class has Mycanvas and adds the Scrollbars.
Field Index:
- Scrollbar vert
- This is the Vertical Scrollbar.
- Scrollbar horz
- This is the Horizontal Scrollbar.
- Mycanvas canvas
Constructor Index:
- ScrollableCanvas( int w, int h )
- This creates a Mycanvas with width w and height h.
Creates the two scrollbars and positions
- them using the Layout Manager BorderLayout.
Method Index:
- void paint( entity ent )
- This is the methods that gets called first from the application applet(
which are individual
- exercises that use these packages. This method just calls the paint()
method of canvas(
- which is of type Mycanvas described before. )
- void newanswer()
- Again, this calls the newanswer() method of canvas.
- void clear()
- When the "clear Button" is pressed, this method is called.
This, in turn, calls the clear()
- method of canvas.
- boolean handleEvent( Event evt )
- This handles the events like SCROLL_LINE_UP, SCROLL_LINE_DOWN,
- SCROLL_PAGE_UP, SCROLL_PAGE_DOWN and
- SCROLL_ABSOLUTE.
- It sets the offset values of the canvas( tx and ty
) and resize the scrollbars using the
- methods resizeHorz() and resizeVert() described below.
- void resizeHorz()
- This method first compares the sum of canvas's width and the
current x-offset value tx with
- the current text_width of the canvas. If the sum is greater
than the textwidth, it updates the
- x-offset value tx.
- void resizeVert()
- This does the same using text_height and ty.
- void paint( Graphics g )
- This just resizes the vertical and horizontal scrollbars.
Summary of the implementation of misc.ScrollableCanvas:
- From the method in the application applet( individual programs
for each programming exercise ) where all the computations are performed,
the paint() method of the misc.ScrollableCanvas is called
when a line( an entity, sentence or table ) is complete.
- The paint( entity ent ) method of misc.ScrollableCanvas
in turn calls the paint( entity ent ) method of Mycanvas
and the rest is as described above.
Source.
algebra Package / misc
Package / Making of the project
/ Project Home Page / My
Home Page
This page has been visited
times since
April 6,1997.