| Author |
Java 2D method + GTK
|
Christopher Arthur
Ranch Hand
Joined: Mar 09, 2004
Posts: 149
|
|
Hi, In an introductory book on Java, a simple method for doing Java 2D graphics is described in these steps: 1. Extend JPanel 2. override void paintComponent(Graphics g) 3. cast (Graphics g) to (Graphics2D) 4. use the J2D API from here. Is this the only way, or was this just a simple introduction? The reason I ask is that there are some faults with it. The two main problems I have are: 1. The drawing flickers every time i move the JFrame containing it. 2. It won't seem to compile with gij under linux! i get the error java.lang.ClassCastException: gnu.java.awt.peer.gtk.GdkGraphics cannot be cast to java.awt.Graphics2D Chris
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
Gcj is wrong here in not using Graphics2D objects. That's par for the course, though; Gcj doesn't conform to every little wrinkle of Sun's Java implementation. You can use (and frankly, should be using) Sun's JDK on Linux, and then of course this problem will go away. The flickering shouldn't happen; are you calling super.paintComponent() in your implementation?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Christopher Arthur
Ranch Hand
Joined: Mar 09, 2004
Posts: 149
|
|
Hi, Now that I've downloaded the Sun JVM, I'm not getting exceptions anymore. No, I'm not calling super.paintComponent() anywhere. When should that be done? Actually the flickering seems to happen every time I click on the frame.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
You should pretty much always call super.paintComponent() as the first line of a paintComponent() implementation. A JPanel should be double-buffered by default, which should eliminate any flickering; are you, by chance, using one of the constructors that lets you turn this feature off?
|
 |
 |
|
|
subject: Java 2D method + GTK
|
|
|