Class ComBox

java.lang.Object
   |
   +----ComBox

public class ComBox
extends Object
implements DrawingObj
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:

      ComBox com = new ComBox(x, y, "Example Comment", font);
      drawingPanel.addCom(com);
      drawingPanel.redraw();
 
It is removed from the drawing panel by:
      drawingPanel.removeCom(com);
 
where 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:
      Font font = new Font("Courier", Font.PLAIN, 12);
 
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.

See Also:
DrawingPanel, addCom, addDrawingObj, redraw

Constructor Index

 o ComBox(int, int, String, Color, Color, 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.
 o ComBox(int, int, String, Font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String parameter.

Method Index

 o draw(Graphics)
This method is to be called from the paint(Graphics g) method of the drawing panel/canvas.
 o getText()
This method is called to obtain the current text string to be displayed in the commentary box.
 o getX()
X coordinate of the top left position of the commentary box.
 o getY()
Y coordinate of the top left position of the commentary box.
 o move(int, int)
Move the top left position of the commentary box.
 o setBackground(Color)
Set the background color of the commentary box.
 o setColor(Color)
Set the text color of the commentary box.
 o setText(String)
Set the text string to be displayed on the commentary box.
 o setTopLeft(int, int)
Set the top left position of the commentary box.

Constructors

 o ComBox
 public ComBox(int topLeftX,
               int topLeftY,
               String str,
               Font font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String parameter. By default, the background color is yellow and the text is displayed in blue.

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.
 o ComBox
 public ComBox(int topLeftX,
               int topLeftY,
               String str,
               Color fg,
               Color bg,
               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.

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.

Methods

 o setText
 public void setText(String str)
Set the text string to be displayed on the commentary box.

Parameters:
str - Text string in the form of class String
 o setTopLeft
 public void setTopLeft(int topLeftX,
                        int topLeftY)
Set the top left position of the commentary box.

Parameters:
topLeftX - Horizontal position of the top left corner.
topLeftY - Vertical position of the top left corner.
 o setBackground
 public void setBackground(Color col)
Set the background color of the commentary box. The background color of commentary box is specified by java.awt.Color.

Parameters:
col - Background color, instance of java.awt.color
See Also:
Color
 o setColor
 public void setColor(Color col)
Set the text color of the commentary box. This foreground color (text color) is specified by java.awt.Color.

Parameters:
col - Foreground color, instance of java.awt.color
See Also:
Color
 o draw
 public void draw(Graphics g)
This method is to be called from the 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.

Parameters:
g - Graphical context from the paint(Graphics g) method of the drawing panel/canvas.
See Also:
Graphics
 o move
 public void move(int x,
                  int y)
Move the top left position of the commentary box.

Parameters:
x - Horizontal position of the top left corner.
y - Vertical position of the top left corner.
See Also:
setTopLeft
 o getX
 public int getX()
X coordinate of the top left position of the commentary box.

Returns:
The X coordinate of the top left corner of the commentary box.
 o getY
 public int getY()
Y coordinate of the top left position of the commentary box.

Returns:
The Y coordinate of the top left corner of the commentary box.
 o getText
 public String getText()
This method is called to obtain the current text string to be displayed in the commentary box.

Returns:
The text string to be displayed on the commentary box.