Java GUI programming tutorial

I am starting to write a tutorial on GUI programming in Java. It’s going to start pretty simple and work into more complicated areas. All of them will be linked from http://markbernard.wordpress.com/2012/07/22/java-programming-tutorials/. The first part of the first tutorial is at http://markbernard.wordpress.com/2012/07/22/java-gui-made-easy-part-1/.

These are not directly related to making games but could help people that want to use Java GUI components around a game.

Please feel free to leave any comments over there or here on whether things are clear or not or if you just don’t agree with the way I did something.

I don’t know what’s behind those links, but I surely hope that it covers how to integrate functionality into a GUI.
Because that has been like a secret for years… It’s the holy grail. :persecutioncomplex:

Edit: I went through it quickly on my crappy phone. I see you’re using swing. Are youmgoing to continue to use swing?
I like swing, don’t get me wrong… I just think that… I’m about the only one. Maybe I don’t know any better :stuck_out_tongue:

Swing is terrible for games… :frowning: JavaFX would be better, although in reality neither are great since most games will require an OpenGL-based UI.

[quote]6. Is JavaFX replacing Swing as the new client UI library for Java SE?
Yes. However, Swing will remain part of the Java SE specification for the foreseeable future, and is included in the JRE. On one hand, Swing is widely used in existing Java desktop applications, but relies on an old architecture, which requires a certain level of expertise and specialization. On the other hand, JavaFX features a set of modern UI controls that can be skinned using standard CSS techniques. While we recommend developers to leverage JavaFX APIs as much as possible when building new applications, it is possible to use JavaFX within a Swing application, allowing developers to extend existing Swing applications.
[/quote]
http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html

What kind of functionality are you haveing problems with? I can take note of it and make a tutorial after this one.

Your not the only one. :slight_smile: I have tried some of the other GUI kits around and while the others may have better performance, none of them are as easy to use as Swing. I find a lot of people they have problems with Swing and it usually stems from LayoutManager problems. I also plan to write a tutorial on LayoutManagers too.

Yes, Swing is terrible for most games. Hoever even if you are writing a 3D game you could still surround your game screen with a Swing interface. Or if you are doing a game that does not require high performance you could also use Swing.

Thanks for the link on JavaFX replaceing Swing. I haven’t had a chance to check out JavaFX yet. I will definitely check it out soon.

JavaFx is pretty nice actually.
It’s quite helpful with not making a hideously tangled mess of things, where in Swing it’s really easy to create such a mess and very laborious to keep things clean.

Thanks erikd. Makes we want to check out JavaFX even more. Gives me an idea to finish the Swing one and then convert it to JavaFX and make a comparison.

To be fair - it takes lots of practice but eventually you’ll learn to design your code such that it stays clean and readable by applying certain conventions. But I must admit - Swing doesn’t make it easy in the slightest. I’ll look forward to see how such things are dealt with in JavaFX 2 when I get around to it. So much other stuff to look into… Can you ever be up to speed in the world of Java development I wonder?

Side note: this blog is all about Swing programming and has some incredibly useful additions to existing components and completely new ones too, among other useful tools such as more flexible layout managers.

http://tips4java.wordpress.com/