I have been playing with the basic game loop class from the tutorials section.

As part of my game's GUI i want to be able to use forms to let the players controll the game.

For example, there will probably be a Shop or market screen that will let players buy and sell goods. I know how to make this as a jFrame form, but i'm unsure how to intergrate this with the actual game rendering prosess.

I have managed to get a jPanel form with lables and text boxes to render onto the game screen, but i cant get mouse events to pass to it (clicking buttons, dragging slideres etc)

Has anyone out there tryed this or got it to work? Is it even possible?

Thanks,Matt

EDIT: Ok, I have a jPanel which shows the current date and time as a jLabel. It has a blue background, a border, and the opacity is set to true.When I tell the component to paint during my render loop, it will ONLY show up if I use paintComponents(myGraphics);This only paints the lable, not the background and border. If I use any of the other paint methods, nothing paints at all.

publicvoidrender(Graphics2Dg){// I have tryed each of these (seperately)this.paint(g); // this does nothingthis.paintComponent(g) // this also does nothingthis.paintComponents(g) // this only renders the controlls on the form, in this case the jLable}

I must admit that I am still new to using the jFrame and jPanel classes :/

I have been playing with the basic game loop class from the tutorials section.

I guess you are talking about my tutorial. There is a sad point with using active rendering this way. You can't use Swing component on Canvas. That mean that you can't add button, label, etc directly on the game screen. You can always create your Gui around the Canvas on the JPanel.

If you were already doing this you should just let the passive rendering do the job, it work well.

Or you could switch to using OpenGL and a widget toolkit which works on it. I've used JOGL with FengGUI for this quite successfully; FengGUI also has a binding for LWJGL, and there are other OpenGL-on-Java widget toolkits.

Is this way of doing things wrong, or is there a better way of doing it, such as your example of using getGraphics() inside each objects render method?

Also, I have been using the netbeans drag and drop gui builder rather than hand-coding my gui elements. There's not anything in the auto generated code that would obviously cause problems with active rendering is there?

You'll have to forgive me, but I'm not sure what all those acronims mean...I'll get on wikipedia

A JComponent's paint method calls paintComponent and paintChildren. You shouldn't need to render the children explicitly, and I think the way you're doing it is buggy anyway (because each component will expect the Graphics object to be transformed to its origin, and probably to have a suitable clip).

Also, I have been using the netbeans drag and drop gui builder rather than hand-coding my gui elements. There's not anything in the auto generated code that would obviously cause problems with active rendering is there?

No idea, never used it. (I've scarcely touched Netbeans, and I actively dislike drag-and-drop GUI builders).

One problem I was haveing was all the swing GUI (when it would render) was always stuck to the origin, reguardless of its positioning.

Cool, I learned something today.

Have you come across TWL? I've not had an in-depth look at how it would intergrate, but it looks like what I want.

Seen it before, never used it. I came across it when I was evaluating widget toolkits for a project which was tied to JOGL, and since it seems to be LWJGL-only I didn't give it more than a glance. There may be someone else here who can comment on it.

I'm going to have to leave this project for a few weeks untill all my 'real' uni work is finished for the year.

I plan to test out the TWI library and play with a few other ideas for rendering GUI, and I'll post my results here when I get them.

One more thing; I'm used to building Event Driven GUIs. If I were to make my own button/checkbox/listView classes from scratch using the Graphics2D lib (and probably images, etc, theres a few threads on the forums about doing this).

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