Class Pen
java.lang.Object
Pen
Class to represent a pen which has a color, width,
and a list of path segments that it should draw.
A pen also knows if it is up or down
Copyright Georgia Institute of Technology 2004
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMove
(int x1, int y1, int x2, int y2) Method to add a path segment if the pen is downvoid
Method to clear the path stored for this pengetColor()
Method to get the pen (ink) colorint
getWidth()
Method to get the width of the penboolean
Method to get pen down statusvoid
Metod to paint the pen pathvoid
Method to set the pen (ink) colorvoid
setPenDown
(boolean value) Method to set the pen down valuevoid
setWidth
(int width) Method to set the width of the pen
-
Constructor Details
-
Pen
public Pen()Constructor that takes no arguments -
Pen
Constructor that takes all the ink color, and width- Parameters:
color
- the ink colorwidth
- the width in pixels
-
Pen
Constructor that takes the ink color, width, and penDown flag- Parameters:
color
- the ink colorwidth
- the width in pixelspenDown
- the flag if the pen is down
-
-
Method Details
-
isPenDown
public boolean isPenDown()Method to get pen down status- Returns:
- true if the pen is down else false
-
setPenDown
public void setPenDown(boolean value) Method to set the pen down value- Parameters:
value
- the new value to use
-
getColor
-
setColor
Method to set the pen (ink) color- Parameters:
color
- the color to use
-
getWidth
public int getWidth()Method to get the width of the pen- Returns:
- the width in pixels
-
setWidth
public void setWidth(int width) Method to set the width of the pen- Parameters:
width
- the width to use in pixels
-
addMove
public void addMove(int x1, int y1, int x2, int y2) Method to add a path segment if the pen is down- Parameters:
x1
- the first xy1
- the first yx2
- the second xy2
- the second y
-
clearPath
public void clearPath()Method to clear the path stored for this pen -
paintComponent
Metod to paint the pen path- Parameters:
g
- the graphics context
-