|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ciips.animation.ComBox
This class composes a commentary box to be drawn on any drawing panel/canvas. The width of the commentary box will be determined by the length of the text string being displayed.
Since this object implements DrawingObj
, it can be added
into the DrawingPanel
by using either the addCom
or addDrawingObj
method. An added commentary box can be
removed by calling the removeCom
or removeObj
method of the DrawingPanel
class.
If the addCom
method
is called, the added commentary box is guaranteed to be displayed on
top of all drawing objects added to the panel using
addDrawingObj
.
Otherwise, if the commentary box is added to the panel using
addDrawingObj
, the last added object will be on top.
Typically, a commentary box can be initialized and added to a
drawing panel and displayed by using the following statements:
It is removed from the drawing panel by:
ComBox com = new ComBox(x, y, "Example Comment", font);
drawingPanel.addCom(com);
drawingPanel.redraw();
where
drawingPanel.removeCom(com);
drawingPanel
is an instance of the class object
DrawingPanel
, x
and y
define
the top left position of the commentary box and font
is an instance of the Font
object, typically a fixed font,
which is declared as follows:
Note that the size-12 courier font is recommended for all situation
since the width of the com box is calculated based on this particular
size font. Otherwise, the dimension has to be modified.
Font font = new Font("Courier", Font.PLAIN, 12);
DrawingPanel
,
DrawingPanel.addCom(ciips.animation.ComBox)
,
DrawingPanel.addDrawingObj(ciips.animation.DrawingObj)
,
DrawingPanel.redraw()
Constructor Summary | |
ComBox(int tlx,
int tly,
java.lang.String s)
|
|
ComBox(int topLeftX,
int topLeftY,
java.lang.String str,
java.awt.Color fg,
java.awt.Color bg,
java.awt.Font font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String
parameter, using the foreground and background colors indicated by
the fourth and fifth parameters. |
|
ComBox(int topLeftX,
int topLeftY,
java.lang.String str,
java.awt.Font font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String
parameter. |
Method Summary | |
void |
draw(java.awt.Graphics g)
This method is to be called from the paint(Graphics g)
method of the drawing panel/canvas. |
java.lang.String |
getText()
This method is called to obtain the current text string to be displayed in the commentary box. |
int |
getX()
X coordinate of the top left position of the commentary box. |
int |
getY()
Y coordinate of the top left position of the commentary box. |
void |
move(int x,
int y)
Move the top left position of the commentary box. |
void |
setBackground(java.awt.Color col)
Set the background color of the commentary box. |
void |
setColor(java.awt.Color col)
Set the text color of the commentary box. |
void |
setText(java.lang.String str)
Set the text string to be displayed on the commentary box. |
void |
setTopLeft(int topLeftX,
int topLeftY)
Set the top left position of the commentary box. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ComBox(int topLeftX, int topLeftY, java.lang.String str, java.awt.Font font)
String
parameter. By default, the background color is yellow and
the text is displayed in blue.topLeftX
- Integer value specifying the horizontal position of the
topleft corner of the commentary box.topLeftY
- Integer value specifying the vertical position of the
topleft corner of the commentary box.str
- The text string to be displayed on the commentary box.public ComBox(int tlx, int tly, java.lang.String s)
public ComBox(int topLeftX, int topLeftY, java.lang.String str, java.awt.Color fg, java.awt.Color bg, java.awt.Font font)
String
parameter, using the foreground and background colors indicated by
the fourth and fifth parameters.topLeftX
- Integer value specifying the horizontal position of the
topleft corner of the commentary box.topLeftY
- Integer value specifying the vertical position of the
topleft corner of the commentary box.str
- The text string to be displayed on the commentary box.fg
- Color of the text in the commentary box.bg
- Color of the commentary box background.Method Detail |
public void setText(java.lang.String str)
str
- Text string in the form of class Stringpublic void setTopLeft(int topLeftX, int topLeftY)
topLeftX
- Horizontal position of the top left corner.topLeftY
- Vertical position of the top left corner.public void setBackground(java.awt.Color col)
java.awt.Color
.col
- Background color, instance of java.awt.colorColor
public void setColor(java.awt.Color col)
java.awt.Color
.col
- Foreground color, instance of java.awt.colorColor
public void draw(java.awt.Graphics g)
paint(Graphics g)
method of the drawing panel/canvas. It uses the graphical context
of the drawing panel/canvas to construct the commentary box on
the drawing panel/canvas.draw
in interface DrawingObj
g
- Graphical context from the paint(Graphics g)
method of the drawing panel/canvas.Graphics
public void move(int x, int y)
move
in interface DrawingObj
x
- Horizontal position of the top left corner.y
- Vertical position of the top left corner.setTopLeft(int, int)
public int getX()
getX
in interface DrawingObj
public int getY()
getY
in interface DrawingObj
public java.lang.String getText()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |