Class IntMatrix
java.lang.Object
|
+----IntMatrix
- public class IntMatrix
- extends Object
- implements DrawingObj
An example implementation of the DrawingObj
interface
that can be added to the drawingPanel (an instance of
DrawingPanel
). Similar to ComBox
, an instance
of this object class is added to the drawing panel by using the
addDrawingObj
method from DrawingPanel
.
This drawing obj can be removed from the drawing panel by invoking
the removeObj
method.
As an example, an instance of IntMatrix class can be added to
an instance of DrawingPanel
, namely drawingPanel
by using the following:
IntMatrix matrix1 = new IntMatrix(4);
drawingPanel.addDrawingObj(matrix1);
matrix1.setColor(....);
matrix1.move(x, y);
....
It can then be removed from the drawing panel by:
drawingPanel.removeObj(matrix1);
This class implements a matrix representation with all integer entries.
- See Also:
- ComBox, addDrawingObj, removeObj
-
IntMatrix(int)
- Construct a square matrix with number of rows = number of columns
as specified by the single parameter of the constructor.
-
IntMatrix(int, int)
- Construct a matrix with the number of rows and columns specified by the
parameters of the constructor.
-
draw(Graphics)
- This method has to be defined to fully implement the DrawingObj
interface.
-
drawBox(Graphics, int, int, String, Color, Color, Font)
- This method is used to draw each element of the matrix.
-
drawMatrix(Graphics, int, int, Color, Color)
- This method is only called from the
draw
method which
in turn is called from the drawing panel to draw the matrix based
on the position and color previously set.
-
elem(int, int)
- Get a particular element of the matrix specified by the position
given in the parameters of the method.
-
getX()
- Get the left most position of the matrix.
-
getY()
- Get the top most position of the matrix.
-
incElem(int, int, int)
- Increment the element specified by the first two parameters by the
value specified by the third parameter.
-
move(int, int)
- Move the matrix to the position specified with reference to the top left
corner.
-
printMatrix()
- Print out the contents of the matrix to the stdout.
-
restoreAll()
- Restore all previously highlighted element of the matrix (black and
gray).
-
restoreHighlight(int, int)
- Restore the element which was highlighted using Color.black.
-
restoreHighlight2(int, int)
- Restore the element which was highlighted using Color.gray.
-
setColLabels(String[])
- Set a label to each column of the matrix based on the array of String
passed in as the parameter.
-
setColor(Color, Color)
- Set the foreground and background color for each element of the matrix.
-
setDiag(int[])
- Set the value for each element on the main diagonal based on the
array passed in as the parameter.
-
setElem(int, int, int)
- Assign a new value to the entry specified by the parameters.
-
setHighlight(int, int)
- Highlight an element of the matrix, colouring it to black.
-
setHighlight2(int, int)
- Highlight an element of the matrix, colouring it to gray.
-
setLT(int)
- Assign a value to all elements to the left hand side of the main
diagonal (exclusive).
-
setRowLabels(String[])
- Set a label to each row of the matrix based on the array of String
passed in as the parameter.
-
setTitle(String)
- Set a title to the matrix.
IntMatrix
public IntMatrix(int rows,
int columns)
- Construct a matrix with the number of rows and columns specified by the
parameters of the constructor.
- Parameters:
- rows - The number of rows of the new matrix.
- columns - The number of columns of the new matrix.
IntMatrix
public IntMatrix(int rows)
- Construct a square matrix with number of rows = number of columns
as specified by the single parameter of the constructor.
- Parameters:
- rows - Number of rows/columns of the new matrix.
elem
public int elem(int i,
int j)
- Get a particular element of the matrix specified by the position
given in the parameters of the method.
- Parameters:
- i - The column number of the element of interest.
- j - The row number of the element to be extracted.
- Returns:
- The integer element at row and column specified by the two
parameter.
setElem
public void setElem(int i,
int j,
int value)
- Assign a new value to the entry specified by the parameters.
- Parameters:
- i - The column number of the element that is being assigned a new
value.
- j - The row number of the element that is being assigned a new
value.
- value - The new value of the element.
incElem
public void incElem(int i,
int j,
int value)
- Increment the element specified by the first two parameters by the
value specified by the third parameter.
- Parameters:
- i - The column number of the element to be incremented.
- j - The row number of the element to be incremented.
- value - The amount of the element incrementation.
setDiag
public void setDiag(int value[])
- Set the value for each element on the main diagonal based on the
array passed in as the parameter. The length of the array must
be at least equal to the longest dimension of the matrix and the
matrix must be a square matrix. Otherwise, an exception might be
raised during execution.
- Parameters:
- value - An array of value to be assigned to each of the element
on the main diagonal of the matrix.
setLT
public void setLT(int value)
- Assign a value to all elements to the left hand side of the main
diagonal (exclusive).
- Parameters:
- value - The value to be assigned to the elements.
printMatrix
public void printMatrix()
- Print out the contents of the matrix to the stdout.
MAX_VALUE is represented by #. This method is only used during the
diagnostic of the class.
setHighlight
public void setHighlight(int j,
int k)
- Highlight an element of the matrix, colouring it to black.
- Parameters:
- j - The column of the element to be highlighted.
- k - The row of the element to be highlighted.
setHighlight2
public void setHighlight2(int j,
int k)
- Highlight an element of the matrix, colouring it to gray.
- Parameters:
- j - The column of the element to be highlighted.
- k - The row of the element to be highlighted.
restoreHighlight
public void restoreHighlight(int j,
int k)
- Restore the element which was highlighted using Color.black.
- Parameters:
- j - The column of the element to be restored.
- k - The row of the element to be restored.
restoreHighlight2
public void restoreHighlight2(int j,
int k)
- Restore the element which was highlighted using Color.gray.
- Parameters:
- j - The column of the element to be restored.
- k - The row of the element to be restored.
restoreAll
public void restoreAll()
- Restore all previously highlighted element of the matrix (black and
gray).
setTitle
public void setTitle(String title)
- Set a title to the matrix.
- Parameters:
- title - The new title of the matrix.
setRowLabels
public void setRowLabels(String strs[])
- Set a label to each row of the matrix based on the array of String
passed in as the parameter.
- Parameters:
- strs - The array of String which holds the new label for each
row of the matrix. The length of the array must be equal to the
number of rows of the matrix.
setColLabels
public void setColLabels(String strs[])
- Set a label to each column of the matrix based on the array of String
passed in as the parameter.
- Parameters:
- strs - The array of String which holds the new label for each
column of the matrix. The length of the array must be equal to the
number of columns of the matrix.
drawBox
public void drawBox(Graphics g,
int x,
int y,
String str,
Color fg,
Color bg,
Font font)
- This method is used to draw each element of the matrix. It is only
called from the
draw
method of this class.
- Parameters:
- g - Graphical context.
- x - The left most position of the box.
- y - The top most position of the box.
- str - The text to be displayed in the box.
- fg - Foreground color (text color) of the box.
- bg - Background color of the box.
- font - A fixed font, in particular size 12 plain courier.
This font instance is passed in to avoid font initialization every
repaint.
move
public void move(int x,
int y)
- Move the matrix to the position specified with reference to the top left
corner.
- Parameters:
- x - The left most position of the matrix.
- y - The top most position of the matrix.
getX
public int getX()
- Get the left most position of the matrix.
- Returns:
- The x-coordinate of the topleft corner of the matrix.
getY
public int getY()
- Get the top most position of the matrix.
- Returns:
- The y-coordinate of the topleft corner of the matrix.
setColor
public void setColor(Color fg,
Color bg)
- Set the foreground and background color for each element of the matrix.
The row and column labels are displayed in the inverse color mode.
- Parameters:
- fg - The new foreground color.
- bg - The new background color.
draw
public void draw(Graphics g)
- This method has to be defined to fully implement the DrawingObj
interface. It calls the
drawMatrix
method which
draws the matrix based on the position and color previously set.
- See Also:
- drawMatrix
drawMatrix
public void drawMatrix(Graphics g,
int x,
int y,
Color fg,
Color bg)
- This method is only called from the
draw
method which
in turn is called from the drawing panel to draw the matrix based
on the position and color previously set.
- Parameters:
- g - graphical context.
- x - The left most position of the matrix.
- y - The top most position of the matrix.
- fg - Foreground (text) color for each element.
- bg - Background color for each element.