[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.6

Problem - Refreshing JPanel with BufferedImage Object

Asked by abhishek88 in Java AWT & Swing, Java Programming Language

Tags: Java, Swing, AWT

In 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 :
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
//This is the class whose object i am storing in the vector
public class StoreBufferedImage implements Serializable {
	private BufferedImage bufferimage;
	private int current_index;
	public StoreBufferedImage(BufferedImage bufferimage, int current_index) {
		super();
		this.bufferimage = bufferimage;
		this.current_index = current_index;
	}
	public BufferedImage getBufferimage() {
		return bufferimage;
	}
	public void setBufferimage(BufferedImage bufferimage) {
		this.bufferimage = bufferimage;
	}
	public int getCurrent_index() {
		return current_index;
	}
	public void setCurrent_index(int current_index) {
		this.current_index = current_index;
	}
	
}
 
 
public class TestPanel extends JPanel
{
      public Vector<StoreBufferedImage> undoredo=new Vector<StoreBufferedImage>();
     private BufferedImage img;
     public BufferedImage getImg() {
		return img;
	}
 
 
 
	public void setImg(BufferedImage img) {
		this.img = img;
		repaint();
	}
 
      public void refreshImage(Graphics g)
	{
		if(img==null)
		{
			int w=getWidth();
	        int h=getHeight();
	        
	        img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
	        setImg(img);    
	        
	        Graphics2D gd=img.createGraphics();
	        gd.setPaint(Color.WHITE);
	        gd.fillRect(0, 0, w, h);
	        gd.dispose();
	        
	        
		}
		
		g.drawImage(getImg(), 0, 0, (int)(getImg().getWidth()),(int)(getImg().getHeight()), this);
	}
 
 
	public void paint(Graphics g) {
		super.paint(g);
		refreshImage(g);
		repaint();
	}
       
    public void undoAction()
	{
		StoreBufferedImage sbi=(StoreBufferedImage)undoredo.firstElement();	
	        // i am getting the object properly.
		setImg(sbi.getBufferimage());
		repaint();
		//on repaint new image is not loaded into jpanel
	}
}
 
 
// This is the mouse listener in which i am drawing rectangle in drawbox method (not shown 
// here in which i am simply drawing the rectangle)
 
public class TestMouseListener extends MouseAdapter{
 
	TestPanel tp;
	int count=0;
	public TestMouseListener(TestPanel tp)
	{
		this.tp=tp;
	}
	
	public void mousePressed(MouseEvent e) {		
		super.mousePressed(e);		
		tp.setStartpt(e.getPoint());		
	}
 
	
	public void mouseReleased(MouseEvent e) {	
		tp.setEndpt(e.getPoint());		
		tp.drawBox(false);	
		StoreBufferedImage sbi=new StoreBufferedImage(tp.getImg(),++count);
		tp.undoredo.add(sbi);				
	} 
	
}
 
// I am having undo button in my jframe class (not shown here) . I am calling undoAction method //  of TestPanel to perform undo operation.
 
Related Solutions
Keywords: Problem - Refreshing JPanel with Buff…
 
Loading Advertisement...
 
[+][-]10/30/09 12:58 PM, ID: 25706299Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 03:58 PM, ID: 25707307Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 08:57 PM, ID: 25708337Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 09:11 PM, ID: 25708386Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 11:27 PM, ID: 25708706Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 01:53 AM, ID: 25708912Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 02:04 AM, ID: 25708934Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 02:14 AM, ID: 25708958Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 02:27 AM, ID: 25708994Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Java AWT & Swing, Java Programming Language
Tags: Java, Swing, AWT
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: B
 
[+][-]10/31/09 02:28 AM, ID: 25708995Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 02:40 AM, ID: 25709023Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 02:51 AM, ID: 25709037Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 03:06 AM, ID: 25709066Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 03:13 AM, ID: 25709078Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 03:26 AM, ID: 25709108Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 03:31 AM, ID: 25709120Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 03:32 AM, ID: 25709122Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 05:01 AM, ID: 25709333Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 05:04 AM, ID: 25709351Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 05:07 AM, ID: 25709357Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 05:07 AM, ID: 25709358Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 05:13 AM, ID: 25709384Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 05:19 AM, ID: 25709415Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 05:20 AM, ID: 25709420Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/09 05:58 AM, ID: 25709563Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 09:14 AM, ID: 25710279Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 09:22 AM, ID: 25710307Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/09 11:41 AM, ID: 25710955Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625