Java Graphics.setXORMode(Color c1)

Syntax

Graphics.setXORMode(Color c1) has the following syntax.

public abstract void setXORMode(Color c1)

Example

In the following code shows how to use Graphics.setXORMode(Color c1) method.


/*w  w w.ja v  a2  s .c o m*/
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {

  public void paint(Graphics g) {
    int w = getSize().width;
    int midW = w / 2;

    g.drawString("XOR Mode", 0, 30);

    g.drawOval(7, 37, 50, 50);

    g.setXORMode(Color.white);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(10 + i, 40 + i, 50, 50);
    }

    g.setPaintMode();

    g.drawString("Paint Mode", midW, 30);

    g.drawOval(midW + 7, 37, 50, 50);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(midW + 10 + i, 40 + i, 50, 50);
    }
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new Main());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20,20, 500,500);
    frame.setVisible(true);
  }
}




















Home »
  Java Tutorial »
    java.awt »




BasicStroke
BorderLayout
CardLayout
Color
Cursor
Desktop
DesktopManager
DisplayMode
EventQueue
FlowLayout
FocusTraversalPolicy
Font
FontMetrics
GradientPaint
Graphics
Graphics2D
GraphicsConfiguration
GraphicsDevice
GraphicsEnvironment
GridBagConstraints
GridBagLayout
GridLayout
Image
ItemSelectable
KeyboardFocusManager
LayoutManager
LayoutManager2
Point
Rectangle
Robot
Shape
SplashScreen
SystemColor
SystemTray
TexturePaint
TrayIcon
Toolkit
Transparency