Brian,
Let me see if I understand what you are trying to do...
It looks like your application will have a set of math questions, which have an associated image that you want to paint on a panel in your main application. However, instead of storing the image in your main application, you want to store it in your question object. (Am I right so far?)
If this is correct all you would have to do is this, create your question file like so :
Then in your main class you would have some collection of questions, like an array or vector of questions, and you would set them all up in the beginning of your program by loading each question with its corresponding image ( if you name your images something like "ques0.gif", "ques1.gif", etc. this makes it easier to do with a loop, you can just do something like this :
)
Once you have all the questions loaded with images, you can choose one question to be the current question displayed and then just use its getImage() method to get its image... you can have that image paint to the Panel or the Frame... One way to do this is to make a subclass of Panel ( which I will call ImagePanel ) that stores a image and paints it :
Then use this ImagePanel in your main application to display the image. The flow of the program would go something like this:
- Choose a current question from the collection of questions.
- Get the image from the question and use it to set the image for the ImagePanel.
- Repaint.
- Respond to user input.
- Repeat as necessary.
HTH,
-Nate