guys, apologies for the delay but I've been away from the internet
I really appreciate your help, but the more I try to understand the more confused I get.
On the plus side, I have created an interface and told my main class to implement it. Then the confusion starts.
Most of the stuff I read seems to be extending the JPanel class, but this doesn't feel right and I think is different from your suggestions. I want my objects to draw themselves when they see fit and to do this I think I need the object to be able to draw itself in my window. Is this the right approach?
Do you mind if I start my questions again?
I have created a class (unitWarrior) which has a few methods for calculating its size and position (and other stuff too). I want a method within it to draw onto my window a little image to represent itself. This image should be read from a file (a jpeg file, but pretty small) within the class constructor method. I am currently reading it into a BufferedImage object using imageIO.Read:
Is this the right object to receive my image from the file in the firstplace?
I have created a GUI class which creates the main window and a menu system (which currently isn't coded to do anything, but I reckon 1 challenge at a time).
My main() routing runs:
GUI.showJPanel
which does what I expect and want, so I think is OK, but here is the method:
I haven't shown each of the methods I call as I think they are OK and do what their names suggest.
the main() then creates an object of type unitwarrior and then a second object of type unitwarrior so the two objects can do battle.
One of the methods is for the object to change its position, when this happens I want to update the screen to show the new position.
Now for some questions....
When I create the JPanel, do I need to get the graphics context returned so I can pass it to each unitWarrior instance so it knows where to draw itself? and to do this would I get the showJPanel method to return mainframe which I then pass to each unitWarrior instance (or is there a global-type variable - or is that question betraying my non-oo roots?)
I can't find the Paint method within bufferedImage to override (is that a clue that I shouldn't be using BufferedImage?)
I am really keen to understand this stuff, but everytime I think I see a glimmer it turns out that there are just more layers of confusion - I am coming to the conclusion that I am asking the wrong questions in the wrong way, and please feel free to point me to a book or something if the missing layers of knowledge are too big for a forum to tackle.