[java] Cavas or JPanel for games...

Started by
10 comments, last by Nexster 21 years, 8 months ago
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?
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))...
- Artist on the web -- Lwjgl Ressources & blog -
if sticking to AWT is a must, I''d use a Panel instead of a Canvas

_______________________
http://mill.3dfxsweden.net
_______________________ http://mill.3dfxsweden.net
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
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
hehe,
my experience is that if you are after maximum speed, you shouldn''t use either, just draw straight in to your frame.

JJ.
--
www.javage.net
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
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
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.

***********************
          
Also do not use paint (just make it empty, same with update to) as paint run concurrently to your main thread.

:-)

ujhkfkfk
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.
Thanks for the link. I''ll check it out right now.

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

This topic is closed to new replies.

Advertisement