Archived

This topic is now archived and is closed to further replies.

[java] Cavas or JPanel for games...

This topic is 5584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve gotten a 2D scrolling tile engine up and running using a JPanel and I was wondering if there is a measurable speed increase in using a non-swing component such as a Canvas. I know in not using a JPanel I would have to add my own Double Buffering but is there any other pros/cons to it?

Share this post


Link to post
Share on other sites
quote:
Original post by mill-o
if sticking to AWT is a must, I''d use a Panel instead of a Canvas



Why? The purpose of Canvas is to allow the programmer to do custom graphics. The purpose of Panel is to contain other GUI components. Plus Canvas has one less level of inheritance, so it does not deal with layout managers. By using Canvas that should make your program that much faster.
quote:
API docs on Canvas
A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.


quote:
API docs on Panel
Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels.




---
Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
quote:
Original post by Jiim
hehe,
my experience is that if you are after maximum speed, you shouldn''t use either, just draw straight in to your frame.



Touche. Never thought of trying that. Duh.

---
Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
So what''s faster? Using swing''s double buffering or rolling your own and use AWT? I''m new to Java game programming so take it easy on the flames if it''s already been answered a thousand times.

***********************
          

Share this post


Link to post
Share on other sites
BigSassy-for the most complete explanation of this stuff I would recommend you head over to javagaming.org and check out the 2d forum. All of the intricacies of 2d graphics in both awt and swing are hashed out over there.

But in short any answer would depend on several factors; are you making an applet or an application? What is you target user? What JDK will you be using? If you want to support any java enabled browser then you want to use awt only and it does a mighty fine job on all current systems. From there it gets quite a bit more complicated.

Share this post


Link to post
Share on other sites
quote:
Original post by harleyrana
Hi, there really isn''t that much difference.
But i''d use swing because awt is in effect a depreciated api, and theres alot of work on impoving java2D that focuses on swing.


Wrong. Swing is slower than AWT. However, with the newer versions, the difference may be minimal. Also the AWT will not be deprecated as all Swing classes are derived from it. The big difference is, AWT uses the native platforms built in windowing widgets. Swing uses Java built widgets.

Swing is the preferred method to use for maximum portability. However if you are making a game, go for maximum speed. If you draw right to the frame, a JFrame should be no problem. It is easy enough to experiment though, so you could try both and see which one you like.

---
Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites