Well, let's say I wanted to do a puzzle.

It's not exactly what I'm trying to do, but I think a puzzle is a good way of describing the problem at hand. I want to lay out one new piece every time I choose the "new piece" option from a menu. Obviously the pieces I've already laid down should not move or disappear(until I say so at least). So you might say I got this incremental thing going on, with new images continously being added to my JPanel. I've tried this, and
it did not turn out well:
So, everytime repaint() is called this happens:
public void paintComponent(Graphics g)
super.paintComponent(g);
index=1;//
u =0;//the matrix placeholder for the x-coordinate;
v =0 ;//the matrix placeholder for the y-coordinate;
//x and y are updated elsewhere, and put in their respective slots
if(img[index] = null)
Rectangle rec = this.getBounds();
g.fillRect(0,0,(int)rec.getWidth(),(int)rec.getHeight());
for(temp=0;temp<index;temp++)//draw all previous images along with this
u++;
v++;
g.drawImage(img[index],imgCoordinates[u][v],this);
index++;//the next time a image loads, it's in the next slot
temp = 0;//zero's out so it's prepared for next redraw
//}//end if
}//end paintComponent
I'm sure the solution is quite within reach, but I just dont know where to start. The most important question is probably: Do I need to redraw the entire screen everytime I add another picture, or is it possible to just
draw the new one, leaving the other parts of the screen alone? Must I get involved with threads?
What about seralization? Please expand my knowledge of such things.
Best regards from frosty norway.

Sorry bout the bad coding above. Absolutely terrible. Have not used array's
for a while see. Here's what I actually meant to write:)
   //let's say I have 20 pieces
    private Image[] img= new Image[20];
    private int[] coor = new int[20];
    int x,y //actual x,y screen coordinates
    int u=0;//x coordinates will be stored at only even numbers;
    int v=1; //y coordinates will be stored at only odd numbers;
public void mousePressed(MouseEvent e
     index++;// p.s I have a default image in img[0]
      u =u+2;//2,4,6...
      v  =v+2;//3,5,7...
      img[index] = source.getImage();//get the image
      coor[u]     = x;//store x
      coor[v]     =  y;//store y
}//end mousePressed
public void paintComponent(Graphics g)
    super.paintComponent(g);
    if(img[index] != null)
      Rectangle rec = this.getBounds();
      g.fillRect(0,0,(int)rec.getWidth(),(int)rec.getHeight());
      for(int i=0;i<index;i++)
        g.drawImage(img,coor[i],coor[i+1],this);
}//end for
}//end if
}//end paintComponent
So what's wrong with this picture? As you see, the pieces are Images so they count as objects all right, but they hardly count as components(Image is not a subclass of Component).
Maybe it's time I got involved with Graphics 2D? And I have been wondering about this validate method
also. What's that about?
And last but not least what's a null-layout panel?
Thanks for cooperating.
Tore.

Similar Messages

Maybe you are looking for

  • How to recover lost folders and files - Pls help, help...

    Some days ago I lost all of my 15 GB folders and files that stored in my Macbook Pro hard drive called DATA.  I brought my Macbook pro to an experienced computer tecnicians who providing data recovery services. To his and my suprise, after checking,

  • How do I add a new device to my existing email?

    How do I add a new device to my email account?

  • Why does the save page command create a new folder

    I am new to CS5. When I "save" a file I've modified, or use "save as" - either one seems to save the page in a complete folder including all graphics, etc. Want to merely save the page with its corrections in the usual way. Is there a setting in CS5

  • USMT Copies Data but does not restore data.

    Can someone help me to shed some lite on a problem we are having?  I am running an OSD task in SCCM2012R2.  The Task Has the USMT option selected and enabled.  When I run the OSD task on workstation I can see it run, I can even go to the directory an

  • Real web sharing

    Though there are "tons" of posts about this, I cannot find one that speaks to my level; nor one that seems to really fix the web sharing "Forbidden: You don't have permission to access /~shortname/ on this server" conundrum. I'm brand new to OS 10.5.