classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GdkGraphics extending Graphics2D?


From: Robert Schuster
Subject: Re: GdkGraphics extending Graphics2D?
Date: Fri, 04 Mar 2005 21:18:30 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.5) Gecko/20050107

Hi,
if I only could find where I read that for J2SE (>=1.2?) you always have a Graphics2D instance. I swear I have read it once.

The argument for is Sun's (and IBM's) doing unfortunately. Since 1.2(?)
JComponent.paint() gets passed a Graphics2D object in the majority of
cases[1] and people are writing production code such as the following
example habitually.

 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.draw(new Rectangle());
 }

Worse is that publications teaching usage of Swing encourage this usage.

It's true, I never think twice before casting a Graphics to Graphics2D. This works in all places where you can get such an instance (e.g. Image.getGraphics(), certain printing related classes).

cu
Robert




reply via email to

[Prev in Thread] Current Thread [Next in Thread]