I have an application that is a Maths Game for kids. Since I'm in college, I've usually only had a god object for all my past projects but for this applciation I've split my code into multiple classes:
MathsGame.java
: main class which initialises components and constructs and controls the UI.DiffScreen.java
: contains methods for use on the difficulty selection screen.GameScreen.java
: contains methods for use on the game screen.EndGameScreen.java
: contains methods for use on the end game screen.MigJPanel.java
: extendsJPanel
and sets layout toMigLayout
and adds a matte border.
Each screen that the 3 XScreen classes control is simply an instance of MigJPanel
and screens are switched to using a CardPanel
container JPanel
.
I'm wondering how I can divide my code to each class so that they are properly abstracted but I'm not entirely sure how to approach this.
Should my 3 screen classes be extending from my
MigJPanel
so these then can be instantiated?So instead of having my
DiffScreen
,GameScreen
, andEndGameScreen
classes solely containing methods related to each screen which are then called fromMathsGame
, each screen will control itself within its own class.If yes to the previous question, should the UI components for each screen be made inside that screen's class?
At the moment, all components for each of the three screens are created in my
MathsGame
constructor. This makes the connection between a screen and the class which 'controls' (I use this word very lightly at the moment) it even further apart. So each screen is just an instance ofMigJPanel
whose components are constructed inMathsGame
. The only relation theEndGameScreen
class—for example—has to the End Game screen is that when theMathsGame
causes the End Game Screen to be displayed, anything done there makes a method inEndGameScreen
be called fromMathsGame
.
I hope I explained myself well. If not, leave a comment and I'll clarify. Any help would be greatly appreciated!