I have made a framework in java2d. At this time it is mostly for me but that can be changed.

A brief introduction to its design:The main class is a Screen. Subclass it for each game state (menu, profiles, high scores, actual game, inventory screen etc). It takes care of updating and painting.Also it listens (with empty methods like an adapter) to mouse and keyboard, simply override what you need and you will be notified. The screen controls the flow between screens, you can goto and call other screens.

So far nothing special. But, a screen can have what I call SubScreens. A SubScreen is a small rectangle that is painted, updated and informed of input events.A SubScreen can be invisible. Then it will not be painted(!!!) :-)A SubScreen can be disabled, then it will not get input events.A SubScreen can be focusable, then it can receive keyboard focus. (some other rules for this also applies, if no object have focus, the subscreen under the mouse gets the keyboard events first and can consume it).A SubScreen operates inside it's own coordinate system. This means that when it gets mouse events they are translated to be relative its local origo. This also holds true for painting. So paint from 0,0 and then move the SubScreen around, it still works.

I have made a number of special subclasses from SubScreen:FocusableSubScreenLabelStyledSubScreen (for widgets that have text)TextField (single line of editable text)Button (you still have to paint it to make sense, just override the paint method)Checkbox

Also, a subscreen can implement the interfaces DragSource and/or DragTarget. When dragged from it returns a Draggable object (interface draggable). When dropped on a SubScreen implementing the DragTarget interface, this object is notified. You still have to do the plumbing behind. But it works very well for the inventory system I am currently working on.

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