java - Graphics2D does PostModern -
in following code changing fill
draw
produces unexpected results. attached image demonstrates undesired appreciated postmodern effect caused draw
ing red , green rectangles.
the affine transform should not part of problem, holmes said, once rule out other possibilities ... so, explain transform. solved bunch of equations figure out how make window show cartesian coordinate system (-2, -2)
in lower left , (+2, +2)
in upper right.
this self-contained example. try changing of draw
s fill
or vice versa achieve own custom art can frame in oracle office.
i using java se 7, jdk 1.7.0_21!
import java.awt.borderlayout; import java.awt.color; import java.awt.graphics; import java.awt.graphics2d; import java.awt.geom.affinetransform; import java.awt.geom.rectangle2d; import javax.swing.jcomponent; import javax.swing.jframe; public class g { public static void main (string [] args) { jframe frame = new jframe(g.class.getcanonicalname()); jcomponent component = new jcomponent() { private static final long serialversionuid = 1l; @override protected void paintcomponent (graphics g) { super.paintcomponent(g); graphics2d g2 = (graphics2d) g.create(); affinetransform xform = new affinetransform(getwidth() / 4, 0, 0, - getheight() / 4, getwidth() / 2, getheight() / 2); g2.settransform(xform); paint2d(g2); g2.dispose(); } protected void paint2d (graphics2d g2) { g2.setcolor(color.red); g2.draw(new rectangle2d.double( 0, 0, 1, 1)); g2.setcolor(color.green); g2.draw(new rectangle2d.double(-1, -1, 1, 1)); g2.setcolor(color.blue); g2.fill(new rectangle2d.double(-1, 0, 1, 1)); g2.setcolor(color.yellow); g2.fill(new rectangle2d.double( 0, -1, 1, 1)); } }; frame.setlayout(new borderlayout()); frame.add(component, borderlayout.center); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setsize(400, 400); frame.setvisible(true); } }
it 1 unit default stroke setting. increased coordinate space -20
+20
in each dimension , drew 10
unit wide , high rectangles confirmed problem image below shows.
Comments
Post a Comment