Jump to content
  • Advertisement

Archived

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

Nexster

[java] Cavas or JPanel for games...

This topic is 5795 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
Advertisement
Canvas is AWT, so it''s very very faster... you can add double buffering to it (using paint(Graphics g) and update(Graphics g))...

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
Also do not use paint (just make it empty, same with update to) as paint run concurrently to your main thread.

:-)

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!