Although a lot of people think JavaFX is better, Swing® works perfectly well for what it is designed for, viz desktop GUI applications. Please explain what “drawbacks” you found and what problems you encountered. Also tell us what sort of game you are writing. You should be able to get Swing® to work for your game.
I was trying to incorporate frames rates into the game along with JComponent, like JButton, JPanel, etc.
In C/C++ I would just erase the whole canvas and then redraw everything based on frames.
I am guess Swing doesn't use this line of logic to update its object.
So I kept running in problems with Component wouldn't draw at all or if I add one component, the other disappear although they are clearly added in a sequence that can be seen.
Or I could be using Swing entirely incorrect way. LOL
Start with a simple GUI program before you try something with lots of redraws:
Create a JFrame.
Create a JPanel and add it to the JFrame.
Create your buttons, etc., and add them to the JPanel using the appropriate layout manager.
Pack the JFrame.
Make the JFrame visible.
Swing uses "layout managers" to add components to a panel. Depending on the layout manager you use the components will be displayed differently.
By default the content pane of the frame uses a BorderLayout, so that is a good place to start.
I would guess you want a main JPanel where you do your custom painting. You can add this to the "CENTERr of your frame.
Then you might have another panel containing the other Swing components and you add this panel to the "PAGE_END" of the frame.
Read the section from the Swing tutorial on Layout Managers. You might want to start with the section on using a BorderLayout for working examples to get you started.
The tutorial also has a section on "Custom Painting" you should read.
Frankie Law wrote:Or I could be using Swing entirely incorrect way. LOL
Yes, I think that's the main drawback you're encountering. It's not really fair to complain about something when you haven't really made an effort to learn how to use it. Now you haven't posted code for anything you've tried so far, but my guess is that you are going down the same road that many other people have gone down. You're struggling to make things work when what you're trying to do is completely at odds with how Swing actually works -- again, that's my impression.
But quite likely you didn't realize that there would be some learning involved before you could write working code. I think it would be a good idea for you to work your way through the Swing tutorial -- when you see the tutorial you'll also see that there's a lot to be learned. I know that instant gratification is a powerful need, though, so if you want to go the route of throwing together some non-working code and asking people here to point you in the right direction to get out of the mess, we do that a lot too. There are different ways to learn, after all.
Frankie Law wrote:Or I could be using Swing entirely incorrect way. LOL
Yes, I think that's the main drawback you're encountering. It's not really fair to complain about something when you haven't really made an effort to learn how to use it. Now you haven't posted code for anything you've tried so far, but my guess is that you are going down the same road that many other people have gone down. You're struggling to make things work when what you're trying to do is completely at odds with how Swing actually works -- again, that's my impression.
But quite likely you didn't realize that there would be some learning involved before you could write working code. I think it would be a good idea for you to work your way through the Swing tutorial -- when you see the tutorial you'll also see that there's a lot to be learned. I know that instant gratification is a powerful need, though, so if you want to go the route of throwing together some non-working code and asking people here to point you in the right direction to get out of the mess, we do that a lot too. There are different ways to learn, after all.
Wow, I actually felt low ball reading this. This is like saying to a baby "why can't you still not walk"
Sorry for even asking the question. Never coming back here again.
If you're doing graphicky game stuff, like a side scroller or platformer for example, the usual technique is to simply draw (as Tim suggests) onto the canvas, rather than trying to use the pre-built Swing classes. Those classes are intended for producing applications for the main part.
So you'd have a game loop, and redraw the bits of the screen that have changed.
Well, that is your problem, not the problem with the answer.
The tone of your question was that Swing was full of "drawbacks".
The answer was simply stating that Swing is different from C/C++.
The answer continued to suggest you need to do some basic reading first BEFORE passing judgement.
The answer then gave you a link to the Swing tutorial so that you could learn the Swing basics.
What you choose to do with the information provided is up to you but in the future questions should be asked with facts about the problem and leave your emotions out of the question.
I have to admit, that when I first started with Windowing systems, it was with SunView, and later with XView*. And I absolutely loved them. So, when OpenLook lost to Motif, and I have to learn yet another Windowing environment, I found tons of "drawbacks" with them too. And then Sun released NeWS, and later TnT running on that of that, that was, admittedly ... well ... just weird.
Anyway, I guess in that sense, every Windowing environment has "drawbacks" -- with it doing stuff differently from your favorite Windowing environment. Those of us, who have had longer professional careers, I guess, tend to not have strong expectations, and hence, don't get as disappointed as easily.
Henry
* Okay, technically, Windows 1.0 for Dos 3.1 (I think) was my first Windowing environment... but that was so bad, I mentally black that out even today...
I once wanted to create a game (engine, and kinda both) using Swing and a JPanel.
https://www.youtube.com/watch?v=2FPLi-DgnBk - A Video of the work when I got somewhere with it
I have since moved on from that project (actually, I am rebuilding it in JavaFX : https://github.com/RepComm/NetGame ), but I do have another project I started after it using Swing as well.
It took quite a bit of trial and error to figure out how to force Swing to render when I wanted it to, but All the above links are my successes.
Please note that they are buggy according to my standards now, as they were me learning how to even get it to work.
I'm a huge fan of immediate-mode rendering (and OpenGL version > 2 ES removes that set of features), and that is why I used Swing at all.
Now I'm using JavaFX, and it certainly does let me mix immediate mode with scene graph well.
I don't mind if you use any of the code in that 7zip project, I figure someone else can learn with it too.
Begun? I actually began with basic modding of a game called Starwars Battlefront (2004), and wanted to try making my own games with the early versions of GameMaker (over at YoYogames.com) back in the days before Studio launched (version 7), when I was 13 year old.
Then I ran into Unity3D around the next year, but I was more of a 3d modeller than a programmer in C#.
A major help for me when developing a game is actually designing so mock-up art before hand, that way I had something to try and implement.
Then the programming just became the struggle to make the art functional, instead of working with no real goal.
I'm a senior in highschool now, but I'm still learning things about Java. I've drawn a lot of inspiration from Unity3d's way of scenegraphing/gui/input, but I don't like C# or C++ much.
My current game project has the goal of actually making a lower learning curve for early programmers, but making developing happen
while you are in the game, that way you don't have to stop programming to test and see your work (and others can see it too, because all the scripting and art is streamed to clients over the server).
That is the goal, it's definitely not ready for use yet though. I just got vector art to stream and recreate over the network yesterday, and my anti-listener input system isn't
fully functional yet.
Henry Wong wrote:...when I first started with Windowing systems, it was with SunView, and later with XView*. And I absolutely loved them. So, when OpenLook lost to Motif, ...
Heh, I was a fan of XView, too, and wasn't happy to see it lose.