Class Pen


public class Pen extends Object
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
    Constructor
    Description
    Pen()
    Constructor that takes no arguments
    Pen(Color color, int width)
    Constructor that takes all the ink color, and width
    Pen(Color color, int width, boolean penDown)
    Constructor that takes the ink color, width, and penDown flag
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMove(int x1, int y1, int x2, int y2)
    Method to add a path segment if the pen is down
    void
    Method to clear the path stored for this pen
    Method to get the pen (ink) color
    int
    Method to get the width of the pen
    boolean
    Method to get pen down status
    void
    Metod to paint the pen path
    void
    setColor(Color color)
    Method to set the pen (ink) color
    void
    setPenDown(boolean value)
    Method to set the pen down value
    void
    setWidth(int width)
    Method to set the width of the pen

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Pen

      public Pen()
      Constructor that takes no arguments
    • Pen

      public Pen(Color color, int width)
      Constructor that takes all the ink color, and width
      Parameters:
      color - the ink color
      width - the width in pixels
    • Pen

      public Pen(Color color, int width, boolean penDown)
      Constructor that takes the ink color, width, and penDown flag
      Parameters:
      color - the ink color
      width - the width in pixels
      penDown - 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

      public Color getColor()
      Method to get the pen (ink) color
      Returns:
      the ink color
    • setColor

      public void setColor(Color color)
      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 x
      y1 - the first y
      x2 - the second x
      y2 - the second y
    • clearPath

      public void clearPath()
      Method to clear the path stored for this pen
    • paintComponent

      public void paintComponent(Graphics g)
      Metod to paint the pen path
      Parameters:
      g - the graphics context