I've created a frame and a panel.
The frame holds the panel - and the panel paints the game on itself.
The thing is - the frame is what holds all the information relating to the game - like where things are and what things exist. Since the panel paints on itself, I need to pass it this information, however, you can't really alter the paintComponent method by adding parameters that it accepts (or so - when I've tried it told me to get lost).
So I've resorted to passing it either each object when the panel is created - so it has its own pointer to say "player", or I've passed it the entire frame so that it has access to all of its public variables, arraylists, objects, etc.
I'm not really sure I should be doing these things - but I'm not entirely sure what else to do.
The Swing Timer is held in the JFrame, and then it calls the panel with .repaint() - then the panel just runs its paintComponent() code. That's how I've got it set up right now.
I'm not quite sure the best way to go about this - or if perhaps I'm doing it just fine.
Edit: also - on the same note - what's the best way to go about holding all the game data? Am I right in creating something that holds all of the information (like the JFrame) and then generally it passes it to other instances of classes when they need to alter that information?
For instance - the JFrame holds "Player player", "ArrayList<Zombie> zombies", "ArrayList<Human> humans", "Tile tiles" - and then just tosses those to methods in other classes when they need to look at it.
This post has been edited by NantucketSleighride: 26 March 2012 - 07:23 PM