<< Labs >> << Assignments >>

An Applet With Graphics

Base Applet:


Graphics class

  • is in java.awt package
  • methods used:
    • drawLine(int x1, int y1, int x2, int y2)
      Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
    • setColor(Color c)
      Sets this graphics context's current color to the specified color.
    • drawRect(int x, int y, int width, int height)
      Draws the outline of the specified rectangle.
    • fillOval(int x, int y, int width, int height)
      Fills an oval bounded by the specified rectangle with the current color.
    • drawString(String str, int x, int y)
      Draws the text given by the specified string, using this graphics context's current font and color.
  • other useful methods:
    • drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
      Draws a closed polygon defined by arrays of x and y coordinates.
    • drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
      Draws a sequence of connected lines defined by arrays of x and y coordinates.
    • fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Fills the specified rounded corner rectangle with the current color.

Add shapes and colors


Add parameters and init method, modify paint method to change params each load (scroll over or reload to see change)



© 2011 The Pain Dealers. All Rights Reserved. Designed by Toxicman. Sponsored by The Pain Radio
Apache: , PHP: 5.2.5