Game GUI

I am wondering how to implement a custom GUI for use in game(java2d applet), only needs limited capabilitys(buttons, textbox, textfield, list…)
Is it best to create a new UI for each component in swing and use setUI(…), or would this be slow. Is it good to subclass canvas/component and just do the functionality urself. It it good to make a class that you have to explicitly tell to repaint and give it events (ie. not a Component of any kind)?.. How is it done on duelboard.com?

tk

I prefer implementing the UI myself. When working with text, most of swing’s UI items lack antialiasing. You’ll end up with a prettier GUI. Another benefit of implementing your own UI is you can easily pack the logic into your main loop for the game. Therefore, you can create a fast, optimized, effecient UI. You can also use nonrectangular components with a custom UI.

The only real problem with a custom UI is that it could actually lead to a speed problem if not implemented correctly. If you just want semi-custom components, set the background to be tranparent or whatever color you need and set the buttons’ icons. This approach works most of the times especially when you don’t need the funcionality that a custom component has.

I wouldn’t recommend setUI(…) unless you already the files to set swing’s look&feel.

so do i extend Component?..

I have made a kinda textfield component before where it paints itself onto the screen in the main rendering method, and it is given some event info each frame, is this the way to go?

First, do you mean JComponent or Component? If your using swing, you should descend from JComponent. As for extending either of the clases, use them if your goal is a completely custom componen. If you just want a semi-custom component, just modify the existing classes in Swing through each class’s respective mutator methods, set*(…).

Most commercial games implement their own GUI ontop of their game render loop.

Trying to make ane xisting GUI system (eg Swing or AWT) cooperate with it is generally too much trouble for the limited GUI needs of a game.