aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help please" Watch "Help please" New topic
Author

Help please

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I currently have a Frame will a bunch of panels. I am trying to paint an image to one of those panels from another class file. How can I do this without Swing? And if It can not be done without swing how can I do it then.
I'm postin ght two class files files below.
I received some great help from Nathan and Bryan about painting to a Canvas or Frame, but this is not what I need. I need to add an image from one class file to a preexisting Panel within a frame.

And here's the main
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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:

  1. Choose a current question from the collection of questions.

  2. Get the image from the question and use it to set the image for the ImagePanel.


  3. Repaint.

  4. Respond to user input.

  5. Repeat as necessary.


  6. HTH,
    -Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Nate,
I've been following your lead and have been successful loading five questions into an array. The only problem is when I go to add the images as a handle to the array, I'm getting a null Pointer exception. The gifs are in the correct folder.
Here's my code... Thanks... You've really been a big help so far.

Also, could you explain how an array of classes is created when the class is not one when it was created. Here's your code. The part that is giving me the nullpointexception
is questGen[i].setImage(tempImage);
Thanks!!
[This message has been edited by Brian Snyder (edited March 02, 2001).]
[This message has been edited by Brian Snyder (edited March 02, 2001).]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Brian,
You have created the array, but you have not created the items inside the array yet... Here is what you would do instead:

An array is a special type of object in Java that contains a number of references to objects of the type specified when the array was created... however, the original references are set to null for any type of object ( arrays of primitives are all set to their 0 values ). The array is not null, but the objects inside it are... that is why you were getting the exception.
HTH,
-Nate
[This message has been edited by Nathan Pruett (edited March 06, 2001).]
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks Nate!!
I got it working already. My probplem what my design.
Here's how I feel now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help please
 
Similar Threads
Popup Menu
Problem with input
Display image in a BorderLayout
AWT
Still not working..help please.