|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectrectTool
public class rectTool
A rectTool implements the operations performed by a rectangle. It holds the private fields int startX and startY, boolean dragged and int fillType. The variable dragged is set to true only when the method dragAction is called and is set to false otherwise. The fillType is assigned as follows: 1=set the color of the border. 2=set the color of the border and the fill. otherwise only set the color of the fill. It should work with all operating systems and hardware. There are no variances and no security constraints.
Field Summary | |
---|---|
(package private) java.awt.image.BufferedImage |
backupImage
Holds the current image and the saved backup image. |
(package private) java.awt.image.BufferedImage |
curImage
Holds the current image and the saved backup image. |
private boolean |
dragged
initialized to false and set to false in clickAction because the mouse has not yet moved. |
private int |
fillType
initializes fillType to 1. |
java.awt.Graphics2D |
g2D
holds a Graphics2D used in the following methods. |
private int |
prevX
Integer representing the previous x coordinate. |
private int |
prevY
Integer representing the previous y coordinate. |
int |
startX
initialized in clickAction by calling the function getX() and getY() on the MouseEvent mevt. |
int |
startY
initialized in clickAction by calling the function getX() and getY() on the MouseEvent mevt. |
Constructor Summary | |
---|---|
rectTool()
|
Method Summary | |
---|---|
void |
clickAction(java.awt.event.MouseEvent mevt,
main_canvas theCanvas)
Allows the user to click on the canvas, to draw a rectangle. |
void |
dragAction(java.awt.event.MouseEvent mevt,
main_canvas theCanvas)
Allows the user to drag the mouse on the canvas and stretch the rectangle. |
void |
drawRectangle(int x,
int y,
int width,
int height,
java.awt.event.MouseEvent mevt,
java.awt.Graphics2D g2D,
main_canvas theCanvas)
Draws the rectangle and sets the color of the border and the fill. |
boolean |
getDragged()
Returns the current state of the flag dragged. |
int |
getFillType()
Returns the fill type of the rectangle as an int. |
java.awt.Color |
getG2dColor()
Returns the Color corresponding to the Graphics2D g2D. |
void |
mouseReleaseAction(java.awt.event.MouseEvent mevt,
main_canvas theCanvas)
Allows the user to release the mouse and stop drawing the rectangle, which was created by dragging the mouse. |
void |
setFillType(int theFillType)
Sets the fillType to the int passed in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int startX
public int startY
private boolean dragged
private int fillType
java.awt.image.BufferedImage curImage
java.awt.image.BufferedImage backupImage
public java.awt.Graphics2D g2D
private int prevX
private int prevY
Constructor Detail |
---|
public rectTool()
Method Detail |
---|
public void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
clickAction
in interface ourTool
mevt
- holds a MouseEvent to call the getX() and getY() to set
the startX and startY, which are the coordinates that the mouse first
clicks ontheCanvas
- holds a main_canvas that calls the getBufferedImage to
be set to the backup image and current image.public void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
dragAction
in interface ourTool
mevt
- holds a MouseEvent to call the getX() and getY() for the
endX() and endY() variables.theCanvas
- holds a main_canvas to drag the rectangle on.public void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
mouseReleaseAction
in interface ourTool
mevt
- holds a MouseEvent to call the getX and getY to set the
endX and endYtheCanvas
- holds a main_canvaspublic void setFillType(int theFillType)
theFillType
- determines which way to fill the rectangle.
1 = border left_color
2 = fill with right_color
3 = solid left_colorgetFillType()
public int getFillType()
setFillType(int)
public void drawRectangle(int x, int y, int width, int height, java.awt.event.MouseEvent mevt, java.awt.Graphics2D g2D, main_canvas theCanvas)
x
- used to initialize the starting x coordinate of the rectangle.y
- used to initialize the starting y coordinate of the rectanglewidth
- used to set the width of the rectangleheight
- used to set the height of the rectanglemevt
- holds a MouseEventg2D
- holds a Graphics2DtheCanvas
- holds a main_canvaspublic boolean getDragged()
public java.awt.Color getG2dColor()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |