+1  A: 

alt text

You do not need to use XOR at all. Especially if you have the two layers separated, it's much easier than that.

// Opaque
private Composite paintMode = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
// transparent; erases the foreground image allowing the background image through    
private Composite eraseMode = AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f);

Then when it comes time to draw:

if (drawing) {
       graphics.setComposite(paintMode);
   }
   else {
      graphics.setComposite(eraseMode);
   }

Then paint like normal. I have a full source code example I can share if you'd like.

I82Much
Thanks for your reply! But I may not be clear on my earlier post. The 2nd layer that I was using has a white background. If the user wants to erase a line I just basically draw a line in white which matches the background color for the 2nd layer. What I really wanted to happen is when I draw the 2nd layer (sketchImage) I don't want the white to draw on my final image. I set the XOR mode to white before I draw the second layer so that it uses the same color of the backgroundImage. Which lead to the problem I was trying to solve.
dan
I think this is what I need to do: filter white to transparenthttp://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png
dan
Try what I'm suggesting - trust me, it works. The naive thing to do is to paint over the top layer with the same color as the background layer. But a better solution is to instead *erase* the top layer, letting the bottom layer shine through. It's much simpler, and will be a lot easier to reason about.My method basically does what the linked image does - by setting the alpha composite to clear, anything you draw on the image instead erases (sets to transparent) that section of the image.
I82Much