The Artima Developer Community
Sponsored Link

Java Answers Forum
paint over an image

3 replies on 1 page. Most recent reply: Apr 16, 2002 7:13 PM by ocd

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
ocd

Posts: 3
Nickname: ocd
Registered: Apr, 2002

paint over an image Posted: Apr 11, 2002 11:48 PM
Reply to this message Reply
Advertisement
I have a frame in to which I add a JComponent. The Jcomponent will draw some picture. But when I try to draw a new picture aside the old picture drawn previously. The old image just disappears. How do I save the old picture so that I can paint two pcitures side by side? Thanks for the help.


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: paint over an image Posted: Apr 13, 2002 10:26 AM
Reply to this message Reply
Well, the default layout for a Frame is BorderLayout. When you add a Component to the frame not mentioning the region, the layout defaults it to be BorderLayout.CENTER. Thats why the old image disappears while the new image takes up all the space. I would try this:
theFrame.add(theJComponent, BorderLayout.WEST);
theFrame.add(theOtherJComponent, BorderLayout.EAST);

ocd

Posts: 3
Nickname: ocd
Registered: Apr, 2002

Re: paint over an image Posted: Apr 16, 2002 7:10 PM
Reply to this message Reply
Thanks for replying. But that wasnt really the problem that I have. check out this pieace of codes

....headers....
....and other stuff......

priavate int x,y,id;
priavte boolean start = true;

//constructor set x = y = id = 0;

public void paint(Graphics g){
if(start == true){
buffer = createImage(100,100);
gBuffer = buffer.getGraphics();
}
gBuffer.drawImage(images[id],x,y,this);
}

public void paintImage(int x,int y, int imageID){
start = false;
this.x = x;
this.y = y;
this.id = imageID;
repaint();
}

now.. somewhere below i call paintImage() twice.

paintImage(0,0,2);
paintImage(10,0,5);

I only see one image drawn at coordinate 10,0. i know I should have gotten two...

why? and how to fix it so that I get two images drawn next to each other. This problem bugs me every second.. please help..thanks !

ocd

Posts: 3
Nickname: ocd
Registered: Apr, 2002

Re: paint over an image Posted: Apr 16, 2002 7:13 PM
Reply to this message Reply
well i need to add g.drawImage(buffer,0,0,this) in paint() method.. but that wasnt the problem

Flat View: This topic has 3 replies on 1 page
Topic: I/O file reading into a singly LinkedList Need Help Previous Topic   Next Topic Topic: Array of Array

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use