Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jsmwoolf

macrumors regular
Original poster
Aug 17, 2011
123
0
Sorry if I'm asking too many questions in a short amount of time, but I was wondering if its best to use the Graphics class or Graphics2D class?
 
Yes, it's definitely better to use one of those. If you want an opinion on which one, you'll have to be more specific.

-Lee
 
How about if the shape always changes? The graphing part of my Calculator app uses the Graphics class for drawing the coordinate plane. However, I plan on using Graphics2D for drawing the shapes because it can deal with complex shapes.

Even though this question doesn't necessarily relate to this post, but it is possible with either class to restrict drawing within a Dimension object so that once it passes a point, it would no longer draw?
 
How about if the shape always changes? The graphing part of my Calculator app uses the Graphics class for drawing the coordinate plane. However, I plan on using Graphics2D for drawing the shapes because it can deal with complex shapes.
Do you realize that Graphics2D is a subclass of Graphics? So any method Graphics provides is also provided by Graphics2D.

Have you looked at any examples using Graphics2D to draw shapes? Such as one of the chart/graph packages I mentioned earlier.


Even though this question doesn't necessarily relate to this post, but it is possible with either class to restrict drawing within a Dimension object so that once it passes a point, it would no longer draw?
Do you mean clipping? Like with the Graphics2D methods clip(), clipRect(), or setClip()?

What reference docs are you consulting for drawing with a Graphics or Graphics2D? What books or tutorials have you used up to this point?
 
Have you looked at any examples using Graphics2D to draw shapes? Such as one of the chart/graph packages I mentioned earlier.

Yes, I have looked on Oracle Java section, on their online documentation for Java, and on online forums. And yes, I also know that Graphics2D is a child class of Graphics. However, aren't there times when it's appropriate to use Graphics instead of Graphics2D?

Do you mean clipping? Like with the Graphics2D methods clip(), clipRect(), or setClip()?

Did some research and yes I meant clipping. I drew a rectangle based off of a point(which is the starting point for the rectangle, not the origin) and set the size based off a Dimension object. I declared the object like this using this Constructor:

Code:
Rectangle(Point p, Dimension d)

I suppose clipRect would be my best option as I tied the dimension with the Rectangle object?
 
Yes, I have looked on Oracle Java section, on their online documentation for Java, and on online forums. And yes, I also know that Graphics2D is a child class of Graphics. However, aren't there times when it's appropriate to use Graphics instead of Graphics2D?

Think it through. Graphics2D can do everything Graphics does, and more. This isn't just a marketing pitch, it's an actual API guarantee because of the subclass relationship. So think of a reason why you'd use a Graphics with fewer features, instead of a Graphics2D.

The only reason I can think of is if you're writing retro-code, which must run on a JVM version before Graphics2D was introduced. In that case, the reason for not using Graphics2D is because it doesn't exist on the target JVM.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.