Set Drawing Mode To XOR Example
- /*
- Set Drawing Mode To XOR Example
- This java example shows how to set drawing mode to XOR instead of overwrite
- mode using setXORMode method of Graphics class.
- */
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Graphics;
- /*
- <applet code="SetXORPaintModeExample" width=200 height=200>
- </applet>
- */
- public class SetXORPaintModeExample extends Applet{
- public void paint(Graphics g){
- /*
- * usually, the new drwaing objects overwrites the previously
- * drawn objects. Setting drwaing mode to XOR mode makes sure
- * that the existing contents will always be displayed and will
- * be XORed with the new objects.
- *
- * To set mode to XOR mode, use
- * void setXORMode(Color c)
- * method of Graphics class.
- */
- //setForeground(Color.RED);
- g.setXORMode(Color.GRAY);
- g.fillRect(10,10,50,50);
- g.fillRect(20,30,50,50);
- /*
- * To set overwrite mode, use
- * void setPaintMode()
- * method of Graphics class.
- */
- g.setPaintMode();
- }
- }
Example Output




