Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  Quick Question  (Read 2664 times)
0 Members and 1 Guest are viewing this topic.
Offline subless

Junior Newbie





« Posted 2012-09-10 06:48:34 »

I'm currently learning java so I can build a game and I have a little question.
When wanting to create a java game window that shows up on the users desktop, what are the best packages to use: Swing or AWT?

Also can someone please explain the difference between the JPanel, JFrame, and JWindow?
Thanks
Offline HeroesGraveDev

JGO Kernel


Medals: 309
Projects: 11
Exp: 3 years


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


« Reply #1 - Posted 2012-09-10 07:00:12 »

JUST SAYING, I MAY BE WRONG, THIS IS JUST WHAT I HAVE HEARD!

A JPanel goes inside a JFrame/JWindow.
A JFrame/Window is the actual container.
A JWindow can be fullscreened (but is a little glitchy)

I recommend just using JPanel and JFrame unless you want fullscreen

Obviously, I favour Swing over AWT, but in the end (LWJGL) Display WINS!*

*For games, not GUI.  Wink

Offline philfrei
« Reply #2 - Posted 2012-09-10 07:35:59 »

I pretty much agree with HeroesGraveDev. I also recommend Swing.

I've got the following link bookmarked, as I find it hard to remember all the Swing components and their details.
http://docs.oracle.com/javase/tutorial/uiswing/components/index.html

A JFrame is a "Top Level Container".  You can get a good explanation of JFrame in the section: "Using Top-Level Containers." I've never used a JWindow. I should look into it!

A JPanel is a container in which one can draw and/or put other components (such as buttons, sliders, textfields, etc.). It is possible to draw on a JFrame, but you have to get to a special layer of JFrame. I find it simple enough to just add a JPanel to a JFrame and go from there. Separating out the "top-layer" functionality from the game play is most often the right way to go anyway. If your game is mostly on a JPanel, then it is easier to make top-level changes such as creating an Applet version of the game.

If you are only intending to draw animations, and not place any components like buttons or labels, one can use a JComponent instead of a JPanel. But for getting started JPanel's are a pretty decent, all-purpose solution.

Welcome to JGO! I hope you find a lot of great info and inspiration here.

"It's after the end of the world! Don't you know that yet?"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2012-09-10 07:56:05 »

I prefer Canvas over JPanel for the actual game window.

Offline ReBirth
« Reply #4 - Posted 2012-09-10 12:03:42 »

Here you go another Canvas supported. Me! I never do a benchmark but with my feel I can tell canvas is faster, at least here.

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2012-09-10 17:45:49 »

Why use the higher abstraction layer of the JPanel, if the lower one gives you everything you need: Use Canvas (IMO, somehow "convention" too)

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2012-09-10 22:19:52 »

Whoa so much confusion in this thread. Here's a brief overview:

- Swing is built on AWT. Swing draws its components using AWT's Graphics object, so there's no point in using Swing unless you want a "pretty" and cross-platform GUI (buttons, dropdowns, etc...)

- @philfrei, JFrame extends JWindow, so they are virtually the same except JFrame has the decorations (title bar, border, X/min/max buttons)

- JPanel is a container used for organizing GUI elements, NOT to draw into as millions of online tutorials teach >.>

- Since Java2D (AWT) is somewhat slow, it's best to not use Swing (you don't need it, it's best to build your own GUI) and use the purest abstraction: java.awt.Canvas as mentioned by jonjava and co.

For more information on how to make Java2D games, read this post.

For more information on LWJGL, read this post.

Offline philfrei
« Reply #7 - Posted 2012-09-10 23:34:53 »

@ra4king -- Thanks for clearing things up. But I think saying JPanel is NOT for drawing upon is slightly inaccurate. JPanel allows you to draw on it! Why would a component that allows drawing NOT be for drawing? True, there are other components that specialize in drawing (I mentioned JComponent in my earlier post in this regard) and are to be preferred if you are only drawing. But if you want to mix in some drawing with some components, JPanel is "OK". That is part of why it is characterized as being "general purpose".

IMHO, for someone just getting started with Java, using JFrame and JPanel is fine. There is plenty enough to learn and accomplish without needing to get into the intricacies of the Full-Screen Exclusive Mode API. But sure, Canvas is preferred for advanced graphics & animation, as is explained in this tutorial:

http://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html

I just think it is good to have a footing in Java basics before tackling this tutorial.
We can agree to disagree.  Kiss

"It's after the end of the world! Don't you know that yet?"
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2012-09-10 23:44:15 »

*All* Swing and AWT components allow you to draw, none of them are final and their paint/paintComponent methods are there Wink

However, it is not meant for drawing.

Either way, there isn't much point to bother with AWT/Swing these days. Just jump onto LWJGL through any of its high level libraries like Slick2D then learn the low-level intricacies of OpenGL.

Offline StumpyStrust
« Reply #9 - Posted 2012-09-11 06:20:26 »

Either way, there isn't much point to bother with AWT/Swing these days. Just jump onto LWJGL through any of its high level libraries like Slick2D then learn the low-level intricacies of OpenGL.

Idk...I think I will just stick to g2d.drawImage(blah blah blah) and everything just magically appears on the screen.  Wink

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nsigma
« Reply #10 - Posted 2012-09-11 11:48:48 »

- @philfrei, JFrame extends JWindow, so they are virtually the same except JFrame has the decorations (title bar, border, X/min/max buttons)

JFrame doesn't extend JWindow!  JFrame extends Frame which extends Window, and JWindow extends Window.  JWindows are really aimed at non-top-level windows - ie. windows that have a parent window.  They shouldn't show up in window lists / task bars, and are used for things like heavyweight popups (menus, tooltips, etc.)

It is worth noting that as well as not showing up in window lists, a JWindow without a parent is not focusable.  If you want an undecorated top-level window you should really use a Frame or JFrame and setUndecorated(true).  A JWindow is not just an undecorated JFrame!

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

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-09-11 15:25:41 »

Ah it extends AWT's Window, not JWindow. Excuse my poor memory Tongue

Offline nsigma
« Reply #12 - Posted 2012-09-11 15:38:26 »

Excuse my poor memory Tongue

Well, I know it's not an age thing!  Tongue

Actually, it's more of an issue telling people they're "virtually the same" - they're treated quite differently in places by the OS.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!