Está en la página 1de 1

#1|1

Java is annoying but not broken




On closer inspection, it was a diamond-style inheritance problem, but was due to my own failure. I was getting the
Graphics2d object by (Graphics2D)getGraphics() instead of casting the one passed to me in the paint routine. Evidently
this was creating a brand new Graphics2D, and hence Graphics base class from the component's canvas, not retrieving
the one we're operating upon. So *I* was effectively causing the creation of a new, unclipped underlying Graphics
interface, not some intrinsic problem in Java. This is a good thing. Debatable whether it's correct, but probably more
useful to be able to do both.

I then found that on swing Jxxx components, it seems that the paints go backwards-forwards (almost) in their entirety
(as per AWT) but then (if opaque) will paint front-to-back or otherwise back-to-front by an entirely different interface,
paintComponent. This is actually almost identical to how I handle such problems in the Skin system! The trick/error is
thus to override paintComponent on swing, not paint in order to do your graphics. I also discovered that the kindle 2 is
using a LayeredPane, and that the JFrames (windows) are not themselves JComponents! Hence they have no
paintComponent and I never thought to use said interface. They have a contentPane (in addition to their rootPane, the
O/S window itself) - one can replace the contentPane with a JComponent derivative that implements a paintComponent.

So that's the way forward! I'm implementing a native version with a JFrame/JLayeredPanel/Panel derivative for our
'native window' !

También podría gustarte