Reputation: 167
I desperately want to know the implementation of draw method in Graphics2D class. I am actually looking for , how the draw method can draw a Shape.
Upvotes: 2
Views: 2130
Reputation: 13841
Maybe this can help: http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
It explains some common algorithms for drawing lines. It's applied math to select what pixels must be painted in an optimized way.
Upvotes: 0
Reputation: 6087
Edit: Sorry, I have misunderstood the question. I thought OP wanted to know how to use draw in Graphics2D, but it seems that the question is more about how the draw method is implemented under-the-hood.
Oracle has a decent introductory tutorial on this kind of thing.
For instance, to create a rectangle, your code would look something like this:
// draw Rectangle2D.Double
g2.draw(new Rectangle2D.Double(x, y,
rectwidth,
rectheight));
Upvotes: 0