Skip to main content
gamedev.net
🔒 Locked

Creating a Menu [Java]

Started by oldulf 1 reply 1.3k views
Original Post
oldulf
oldulf
Hey folks!
Long time reader, first time writer. If this be the wrong place for this topic (beginner problem, mayhaps?), please excuse me.

I'm currently writing a simple 2D game prototype, which will offer user interaction mainly from menu selections with the mouse.
This means that the user sees a list of buttons and clicking one of them either opens a new menu or window (whithin the gamepanel) and so forth.

Consider a button that when clicked needs to change the visibility state of another menu and at the same time turn it's parent container (menu) invisible.

I tried my own implementation from scratch, but it has turned fairly ugly with a lot of if-statements and questionable callback functions. Thus I wonder,
what is best practice when creating a menu system? Java Swing already contains good components such as buttons, was thinking about using
them together with local event handler classes for performing action.


This problem is probably trivial, but I'm yet inexperienced with regards to programming.
TheCompBoy
TheCompBoy
Could you maybe provide a posted code from your project cus else we would just be guessing wild.. So you basicaly want to make a window invisible when button is clicked and new window visible?
PhilLiu
PhilLiu
My approach would be to use the MouseListener/MouseEvent api and just check for click collisions with your button objects.

That is pretty much how swing does it anyway (with a lot more fancy stuff like event handling).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.