|
|
|
Class Scroller
Download It
class Scroller extends java.awt.Canvas
{
// Constructors
public Scroller( );
public Scroller( int W , int H , Font f );
// Methods
public void setSize( int W , int H );
public void setBackground( Color bg );
public void setForeground( Color fg );
public void setFont( Font f );
public void setDelta( int i );
public void Reset( );
public int getX( );
public int getY( );
public void initScroll( String m , int d );
public boolean Scroll( );
public void drawScroll( Graphics g );
}
The Scroller class can be used to handle the fundamentals of text
scrolling. The class can do the actual drawing to the canvas if you choose,
but it does not support double buffering. You can implement the drawing
to the canvas yourself by using the getX( ) an getY( ) results, which
will tell you where the current position of the string will be.
Constructors
Scroller
public Scroller( );
This is the default constructor for the Scroller class.
The width and height of the canvas will be set to 0.
The font will be set to TimesRoman , Bold , 24.
The FontMetrics will be set using the above Font.
The Background Color will be set to Black.
The Foreground Color will be set to White.
Scroller
public Scroller( int W , int H , Font f );
This is the user-defined constructor for the Scroller class.
Parameters:
W - the width of the canvas/applet
H - the height of the canvas/applet
f - the default Font to use
Methods
setSize
public void setSize( int W , int H );
This is used to set the size of the canvas/applet (for use with the default constructor)
Parameters:
W - the width of the canvas/applet
H - the height of the canvas/applet
setBackground
public void setBackground( Color bg );
This is used to set the background color of the canvas.
Parameters:
bg - A Color object
setForeground
public void setForeground( Color fg );
This is used to set the color the message will be drawn in.
Parameters:
fg - A Color object
setFont
public void setFont( Font f );
This is used to set the font type for the message
Parameters:
f - a Font object
setDelta
public void setDelta( int i );
This is used to set the number of pixels the message should
move between iterations of scroll. This is initially set to 5.
Parameters:
i - int representing the number of pixels to move
Reset
public void Reset( );
This is used to reset the state of the applet to not finished. This is used
in conjunction with the Scroll method, which will check to see if it is finished
scrolling the message, then return the value of it's state (finished or unfinished)
getX
public int getX( );
This will return the X coordinate for the current position of the message
getY
public int getY( );
This will return the Y coordinate for the current postion of the message
initScroll
public void initScroll( String m , int d )
This method will determine where the starting X and Y coordinates for the
scroll will be based on the FontMetrics of the message passed in, and the
direction passed in.
Parameters:
m - the message to be scrolled
d - the direction which to scroll the message, from the following options
1 = left to right
2 = right to left
3 = bottom to top
4 = top to bottom
Scroll
public boolean Scroll( );
This method will update the position of the X and Y coordinates, based on the
values previously passed to initScroll if the scroll is not completed,
otherwise it will set the state of the scroller to finished.
Returns:
The state of the scroller ( finished or unfinished )
drawScroll
public void drawScroll( Graphics g );
This method will handle the drawing of the scrolling message
to the canvas. It does not support doulbe-buffering. If you wish to
implement double-buffering you must use the return values of
Scroll( ), getX( ), and getY( ).
Parameters:
g - The applet or applications Graphics object.
Scroller.class
by James Savidge
e-mail: savidge@scsud.ctstateu.edu
7-14-97
|