Background color of the graph is taken to be white but that can be changed. To make sure that the pointer works for transparent gifs like trans.gif, I cover the floor with this color before drawing the real image on it, and the pointer color is what one gets when drawing on that color. In case your image is not transparent and the majority of its dots are red instead of white, then the program should be informed that the background is FF 00 00, in order to gain your desired pointer color when drawing on red.
The priority of applet is speed and memory. It does not care about your discomfort with screen flickering. In first download and repaint() - g is getGraphics() - and the applet will directly draw on getGraphics() through update(g) to paint(g), unless you override update(g). Double-buffering decreases frame rate but is visually more appealing. One draws on bak_g, then copies to (instead of draws on) g. Management would never do that voluntarily.
Once we see that g may not be getGraphics(), confusions about setXORMode are cleared. Basically, if the current context color a=g.getColor() [which can be set by g.setColor(a), or to be the initialized black], after which g.setXORMode(b), then if we draw thereafter on g's dot of color c: c -> a (+) b (+) c. Thus, if a is picked or made to be the "background color" of g, where the majority of g's dots have c=a, then it would turn b after we draw on the background once. On other dots (like a yellow circle in mostly white background), the result is unpredictable, but always reversible before setXORMode is changed. The point is, it is important to be sure that a=g.getColor() is what you think it is before running g.setXORMode(b), otherwise you won't get the planned effects - like getting b when drawing on the background of g.