Paint Modes
Home ] Up ] Introduction ] The Swing Package ] Frames ] Panes, Text & Fonts ] Colors ] Shapes ] [ Paint Modes ] Images ]

 

XOR Mode Example
Simple Animation

 

Normally, when you draw in the Graphics context, it draws the color that you have set for the foreground color.  In other words, this mode overwrites any color that was present before.  This is called Paint mode.

There is also a second mode, XOR mode, which you select with a call:

g.setXORMode(xorColor);

XOR mode changes the behavior in the following ways:

  • If you draw on top of pixels that are already in the current color, then the system changes them to the color specified in the setXORMode call.
  • If you draw on top of pixels that are already in the color of the setXORMode parameter, then the system changes them to the current color.
  • Any other colors are also changed by the system.

If you draw a shape in XOR mode, with a certain color, and then draw it again in the same position with the same color, the effect is as if you hadn't drawn anything in the first place.

 

This page was last modified on 02 October, 2007