Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Differences in extends JComponent, JFrame, JPanel, & Canvas (mega noob question)  (Read 1055 times)
0 Members and 1 Guest are viewing this topic.
Offline unenergizer

Junior Member


Medals: 3
Exp: 1 year


Work hard, practice often, and you will succeed!


« Posted 2013-11-18 05:46:50 »

Hi JGO,

I am writing this thread because I have a question about extending JComponent,, JPanel JFrame, and Canvas.  In many different tutorials, I have noticed authors extending these three different classes in their main class.  Each of these's authors are extending different classes and now it has me wondering which ones I should be extending and why.  Do you choose one of these classes depending on what kind of game your going to make?  All tutorials that I have read have only been 2D so far. I have read it is important to learn 2D concepts and programming techniques before moving on to 3D.  Also I have been learning swing from one of my books, but is it necessary to learn this if I am mainly going to write my own ui components?  Should I still learn swing regardless?

If you have experience in this and you don't mind helping a novice out, then I would sure appreciate your help.  I hope this is relatively easy to answer.

Cheers,
Andrew

JGO is AMAZING!
Steam: unenergizer
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-11-18 06:46:20 »

Using my somewhat limited knowledge of AWT/Swing/Java2D, here is what I know/assume:

JFrame is a window.
JPanel is a general purpose GUI container and/or component.
JComponent is the base class for most GUI component.
Canvas is a special AWT component that has some support for double buffering.

I recommend using Google for more reliable info.

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-11-18 07:14:57 »

JComponent/JFrame/JPanel are part of the Swing gui system, which is newer than AWT, the old gui system (that Canvas belongs to). JPanels are double-buffered by default.

Learning Swing is extremely easy and worth the effort. Even if you do switch to a GUI builder it'll still be helpful info.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nsigma
« Reply #3 - Posted 2013-11-18 11:56:55 »

JComponent/JFrame/JPanel are part of the Swing gui system, which is newer than AWT, the old gui system

Swing is built on top of AWT!

Canvas is a special AWT component that has some support for double buffering.

More important feature of Canvas is that you can get a BufferStrategy from it and therefore use it for active rendering.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline unenergizer

Junior Member


Medals: 3
Exp: 1 year


Work hard, practice often, and you will succeed!


« Reply #4 - Posted 2013-11-19 04:10:51 »

JComponent/JFrame/JPanel are part of the Swing gui system, which is newer than AWT, the old gui system

Swing is built on top of AWT!

Canvas is a special AWT component that has some support for double buffering.

More important feature of Canvas is that you can get a BufferStrategy from it and therefore use it for active rendering.

Would you please explain which is the "best" solution for developing games (and why)? 2d games specifically.

Thanks for the help folks! You guys rock!  Cool

JGO is AMAZING!
Steam: unenergizer
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #5 - Posted 2013-11-19 04:42:18 »

I just realized something, I don't think anyone specifically answered your questions directly. I think it is mostly because Java is a programming language... not a game maker. In other words, those components (like JFrame, JComponent, etc.) just puts a frame into the screen while you, the coder, has to provide the artwork and logic.

Would you please explain which is the "best" solution for developing games (and why)? 2d games specifically.

I think you may be asking the wrong question as... all of these play a part in getting a basic screen to show. There is no technical "best" solution, though double-buffering does help a lot with animation. In other words, whichever one helps you get a screen that you can design on the fastest would probably be the best.

Do you choose one of these classes depending on what kind of game your going to make?

If you are using Java2D, you will be using one of these to create your game. None of these are better than the other solution as they are not based on speed. Some have double buffering which helps you during animations, but that is about as much as you'll get from a frame. You can also control screen-size with it, but you have to be careful as some of the Swing components scale your work while others do not. Research through Google or follow your tutorials closely.

All tutorials that I have read have only been 2D so far. I have read it is important to learn 2D concepts and programming techniques before moving on to 3D.  Also I have been learning swing from one of my books, but is it necessary to learn this if I am mainly going to write my own ui components?  Should I still learn swing regardless?

This highly depends on what you are coding for...

If you are in it strictly to make games, I'd say just find the first solution and go with that.
If you are in it to learn more about Java in general, then by all means, learn Swing.

Writing your own UI components is fine. I usually don't like the layouts that Swing gives to me by default anyway because I find them too limiting. Keep in mind that rolling your own components will ultimately take you longer to actually produce something.

Keep in mind any of these solutions are fine to use, and it won't affect performance for your 2D game...

Oh, and I generalized a lot in this post because they were very technical in the posts above. So, if I were you, I'd pick my favorite tutorial and start coding. There is a lot more to game making than just the screen to use. You still have to look at game loops, animation, sound, controls, etc.

Offline unenergizer

Junior Member


Medals: 3
Exp: 1 year


Work hard, practice often, and you will succeed!


« Reply #6 - Posted 2013-11-19 11:37:28 »

@ ctomni231. AAA+ Answer sir, thank you.

I definitely want to be a professional java developer and I know I need to learn swing. I think the excitement of learning game development makes me want to push everything else aside.  I will do further research on the subject. When I start making my own 2d games I want them to be super polished and animated. I have seen sprite sheets for many snes games and I know what it takes, a lot of work. So I will choose the best for animation unless I learn otherwise. I have the core basics down and I am migrating into graphics, so I apologize if I ask "silly" questions.

Thanks again!

JGO is AMAZING!
Steam: unenergizer
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (39 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (36 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!