Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  creating a gui and handling game windows  (Read 1547 times)
0 Members and 1 Guest are viewing this topic.
Offline Sphinx

Junior Newbie

« Posted 2012-04-08 06:44:25 »

i am working at he moment at a 2d turn basted space strategy game. I need to interact with the windows i draw to the screen but i am not quiet happy how i do it so i would like to get some info how to do it properly.
How it works for me now:
I have an input class which is processing the mouse input.
My game class is pulling the needed mouse information from my input class, and for a mouse click it calls a mouseClicked function in my galaxy class witch handles the logic of the galaxy.
The galaxy class is going through a list with all possible windows if some exist. If one is found where the mouse click happened the click routine of the window is called and the window does what it does with the click.

Overall i have the feeling that i am overdoing something and that there would be a better way to work with my in game windows than that what i am doing now.

Any tips or links that could lead me to a better understanding of this case would be nice.
Offline davedes
« Reply #1 - Posted 2012-04-08 16:37:11 »

Are you using LWJGL or Java2D?

If you're using LWJGL you might rather look into solutions like TWL or NiftyGUI.

If you're using Java2D you could just use Swing/AWT for GUI.

If you're using a homebrew library with your own widgets, your code might look something like this:
    public static Widget getDeepestWidgetAt(Widget parent, int x, int y) {
       if (!parent.inside(x,  y))
          return null;
        for (int i=parent.childCount()-1; i>=0; i--) {
            Widget comp = parent.getChild(i);
            if (comp!=null && comp.isShowing()) {
                if (comp.inside(x, y)) {                    
                    return getDeepestWidgetAt(comp, x, y);
       return parent;

For mouse wheel, click, move, etc. you simply determine the deepest component underneath the mouse and then send the event to that component. For keyboard input, etc. you have to implement a focus system.

Offline Sphinx

Junior Newbie

« Reply #2 - Posted 2012-04-09 07:02:55 »

For the learning effect i am writing everything for myself. So it seems that i am not totally on the wrong way in doing the input handling which is good. Then i can can devote more time in this system to make it better. I would hate it to work weeks on this system and then release it was an to complicated way of doing things.
Pages: [1]
  ignore  |  Print  

DesertCoockie (22 views)
2018-05-13 18:23:11

nelsongames (72 views)
2018-04-24 18:15:36

nelsongames (67 views)
2018-04-24 18:14:32

ivj94 (751 views)
2018-03-24 14:47:39

ivj94 (81 views)
2018-03-24 14:46:31

ivj94 (605 views)
2018-03-24 14:43:53

Solater (97 views)
2018-03-17 05:04:08

nelsongames (170 views)
2018-03-05 17:56:34

Gornova (388 views)
2018-03-02 22:15:33

buddyBro (1048 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!