GUI APIs and Input Events
I'm working on some of my own APIs for game development in Java as both a learning project and hopefully something I can carry through to an actual product. One of the APIs is something like an Input Registry. It is designed to keep track of key/mouse events and notify registered listeners when it's registry changes. I've noticed that different GUI APIs written for Java sort of handle their input events differently. I was wondering if there was a non-GUI API specific way to capture what key/mouse events are happening. I'd like to keep this lower level of the API as separate from specific GUI APIs as possible, so that I can use AWT, SWT, Swing, JFace, or whatever else is out there all on top of the same lower level API.
Is this possible?
Re: GUI APIs and Input Events
You should be able to define your own events and have listeners register with your code. Then define a mapping from key and mouse events to your events. Your code listens for key and mouse events, maps the event to your event and calls the listeners for your events.
Re: GUI APIs and Input Events
Well, since I'm not writing the GUI, and I'm don't want to force the user to use a certain GUI API, I'm confused as to how to make my code listen for input. As far as I know, in order for my code to listen for input events, it has to be added as a listener to a component of the GUI toolkit of the user's choice. I don't know what SWT or JFace use for events (I've only used Swing and little bit of raw AWT), but if they've defined their own, how would I go about making sure my listeners would work in all GUI APIs? Or am I going to have to limit what GUI APIs users can use?
Re: GUI APIs and Input Events
You would write the model to be GUI library-agnostic. The listeners and GUI code would all have to be tailored to the GUI library that you're using.
Re: GUI APIs and Input Events
Ok, that makes sense.
Thank you both.