Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to the <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Graphics2D.html" rel="nofollow">JavaDoc of the Graphics2D</a> class Shapes are rendered according to the following principle:</p> <blockquote> <p>Shape operations</p> <ol> <li><p>If the operation is a draw(Shape) operation, then the createStrokedShape method on the current Stroke attribute in the Graphics2D context is used to construct a new Shape object that contains the outline of the specified Shape.</p></li> <li><p>The Shape is transformed from user space to device space using the current Transform in the Graphics2D context.</p></li> <li><p>The outline of the Shape is extracted using the getPathIterator method of Shape, which returns a PathIterator object that iterates along the boundary of the Shape.</p></li> <li><p>If the Graphics2D object cannot handle the curved segments that the PathIterator object returns then it can call the alternate getPathIterator method of Shape, which flattens the Shape.</p></li> <li><p>The current Paint in the Graphics2D context is queried for a PaintContext, which specifies the colors to render in device space.</p></li> </ol> </blockquote> <p>In short, this means that the <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Graphics2D.html#draw%28java.awt.Shape%29" rel="nofollow">Graphics2D.draw(Shape)</a> method will call your <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Shape.html#getPathIterator%28java.awt.geom.AffineTransform%29" rel="nofollow">TraingleShape.getPathIterator(AffineTransform)</a> method and use the returned <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/geom/PathIterator.html" rel="nofollow">PathIterator</a> object in order to find which points to draw lines between. </p> <p>As such, you will likely be required to implement your own PathIterator implementation that corresponds to your TriangleShape implementation. </p> <p>The above solution may however be more complex then it needs to be. An alternative would be to look into the <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Path2D.html" rel="nofollow">Path2D</a> class which allows you to easily specify arbitrary shapes using simple operations such as lineTo(x,y). Since this class implements the Shape interface you could allow your TriangleShape class to extend this class, or just delegate to it. Here is an example of using the GeneralPath class, which works in a similar way to Path2D: <a href="http://www.roseindia.net/java/example/java/swing/graphics2D/general-path.shtml" rel="nofollow">http://www.roseindia.net/java/example/java/swing/graphics2D/general-path.shtml</a></p> <p>It does however depend on your particular assignment whether this would be an acceptable solution or not. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload