Last week I made a simple java game. At that time, one class extended Jframe and contained data (which included the other three classes, through composition)
Now I'm trying to make the same game, but with several JPanels. One of the panels will be game graphics (basically the old JFrame is compressed into one panel). And other panels will have buttons and text fields.
But I am confused about how sharing / accessing program data will work. Now I have one extensible JFrame class with 3 sub-panels. One of these sub-panels is game graphics, which currently contains all of the Playerβs data.
1) Can I leave data on this panel and access it using getters / setters? (I tried, but could not do anything.)
2) How are games usually laid out? Should I, for example, move the Player data to the JFrame class, which contains all the panels, and add getter / setters there. (Ideally, both players will be used / edited by all panels.)
source
share