AlphaComposite.DST_OUT : AlphaComposite « java.awt « Java by API






AlphaComposite.DST_OUT

 
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

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

public class MainClass extends JPanel {

  public void paint(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);

    int x = 40, y = 40;

    g.setColor(Color.red);
    g.fillOval(x, y, 50, 50);

    Composite old = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT));

    g.setColor(Color.green);
    g.fillOval(x + 30, y + 30, 30, 30);

    g2.setComposite(old);

    g.setColor(Color.black);
    g.drawString("AlphaComposite.DST_OUT", x, y + 80);

  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}
           
         
  








Related examples in the same category

1.AlphaComposite.CLEAR
2.AlphaComposite.DST_ATOP
3.AlphaComposite.DST_IN
4.AlphaComposite.DST_OVER
5.AlphaComposite.SRC
6.AlphaComposite.SRC_ATOP
7.AlphaComposite.SRC_IN
8.AlphaComposite.SRC_OVER
9.AlphaComposite.SRC_OUT
10.AlphaComposite: getInstance(int rule, float alpha)