File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Graphics and animation in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphics and animation in Java" Watch "Graphics and animation in Java" New topic
Author

Graphics and animation in Java

Mani Pava
Greenhorn

Joined: Apr 29, 2008
Posts: 5
Hello,

If anyone can, please give me a way to get some resources(tutorials & examples) related to Graphics2D,Grphics3D and animation stuff in Java.

I've found various materials by searching in the net. But couln't get a nice tutorial with examples.

Thanks in advance,
Mani
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Have you been through the Java Tutorials? You will find 2D there, but I don't think animation.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Trail: 2D Graphics
You'll find an animation under the second paragraph on How to Make Applets followed by a link to the source code.
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
What about hardware acceleration? I've heard that you can only do it using a Canvas because of the createBufferStrategy() method in combination with the GraphicsConfiguration class, but can you do it using Swing components? I've read some about Volatile images, but do not know much about some of the fundamental concepts (i.e. if I just draw to a BufferedImage and then have the JPanel graphic draw that image, is that the same thing, or do I have to allocate the memory in the accelerated graphics memory? Whats the difference?). Sorry for kind of commandeering this thread, but it seems in line with the topic.

Andy
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
I figured it out:

GraphicsConfiguration configuration = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration();

Then, when you want to draw the image:

VolatileImage image = configuration.
createCompatibleVolatileImage(getWidth(), getHeight());
/* assuming you are extending the component */

Check the VolatileImage API for information on checking if the image is available to be drawn on, and make sure to flush the image if you create a new one assigned to the reference to save resources.

This reply is kind of crap in its explanation, but the JavaDocs for the VolatileImage class and createCompatibleVolatileImage method are good.

(The whole reason to use hardware acceleration is to bypass the CPU, as best as I can tell.)

As for how to handle the buffer strategy with Swing components, and if you even need to...
I have no clue.

Andy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics and animation in Java