Show XOR Mode

In this section, you will studied about the XOR mode.
XOR or Exclusive Or returns true only if both its operands have different values. The XOR shows the
uncommon part. We are providing you an example which shows the XOR mode.
The method setXORMode(Color.yellow) of Graphics class sets
the paint mode between the
current color and the new specified color. We have defined four circles showing
the XOR mode on the forth circle. The logical pixel
operations are performed in the XOR mode, which alternates pixels between the
current color and a specified XOR color.
Here is the code of UseXORMode.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UseXORMode extends JPanel {
UseXORMode() {
setBackground(Color.black);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillOval(30, 20, 90, 40);
g.setColor(Color.yellow);
g.fillOval(60, 30, 90, 40);
g.setColor(Color.blue);
g.fillOval(140, 50, 70, 40);
g.setXORMode(Color.yellow);
g.fillOval(100, 40, 90, 40);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Use XOR Mode");
frame.setSize(350, 200);
Container contentPane = frame.getContentPane();
contentPane.add(new UseXORMode());
frame.show();
}
}
|
Output will be displayed as:

Download Source Code

|