> but the real problem lies in refreshImage: you call setImg with an empty image and then proceed to draw it.
thats fine actually
Main Topics
Browse All TopicsIn my program , i am drawing on bufferedimage object and then i am painting it to jpanel.
It is working fine
But as i want to implement undo/redo functionalities. i want to set or change bufferedimage object by new one (retreived from the vector) to the jpanel. I am getting the object from vector but it is not refreshing the jpanel means new image is not loaded into the jpanel.
Here is the sample code :
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
thats correct, you need to make a copy of the image before you add it to the list
http://helpdesk.objects.co
in mouse released, i add the image drawn on jpanel to the vector .
and
then on clicking undo button , i call undoAction method
Now why all the elements of the vector are updated with the current image.
In code , on every mouse released event , i am adding the current image to the last in the vector and then drawing the final rectangle.
That Code is already posted in the previous comments.
undo action is setting the first element of vector to the jpanel
I am retrieving the first element for now . once i get the first element i correct that code to perform undo operation.
I am getting the first Element as the current image drawn on the jpanel which is not correct but i should get the image containing the first rectangle drawn on the bufferedimage object on jpanel when i start the program and draw the first rectangle.
Hope you got it.
ya i have only one reference of buffered image in my panel
but
i am saving the previous reference in the vector first
then i am calling draw Box method which changes and update the buffered image object,
So you want to say that changing in the bufferedimage object also changes the images in the vector
If that is the case then plz give the proper solution or code so that i can proceed further.
I got stuck in this problem.
I want to store the copy of image in the vector because i want to get the previous image from the vector whenever user presses undo button
The problem that was occuring is
whenever i add element to the vector , all the images of the vector are replaced by the current image because of all points to same image (reference problem) so i am not getting the desired output.
Therefore first i create the copy of the image and then store the image in vector.
so next time whenever i add element to the vector , it won't change all the images and
it just add that element to the last.
Copy BufferedImage object (means making clone of it) and storing it in vector have solved my problem.
Business Accounts
Answer for Membership
by: CEHJPosted on 2009-10-30 at 12:58:32ID: 25706299
>>public void paint(Graphics g) {
should be
public void paintComponent(Graphics g) {
but the real problem lies in refreshImage: you call setImg with an empty image and then proceed to draw it. What happened to your vector of images?