AlphaCompositeRules.java.


AlphaComposite alphaComposites[] = {
AlphaComposite.Clear, 
AlphaComposite.getInstance(AlphaComposite.CLEAR, .5f),

AlphaComposite.DstIn, 
AlphaComposite.getInstance(AlphaComposite.DST_IN, .5f),

AlphaComposite.DstOut, 
AlphaComposite.getInstance(AlphaComposite.DST_OUT, .5f),

AlphaComposite.DstOver, 
AlphaComposite.getInstance(AlphaComposite.DST_OVER, .5f),

AlphaComposite.Src, 
AlphaComposite.getInstance(AlphaComposite.SRC, .5f),

AlphaComposite.SrcIn, 
AlphaComposite.getInstance(AlphaComposite.SRC_IN, .5f),

AlphaComposite.SrcOut, 
AlphaComposite.getInstance(AlphaComposite.SRC_OUT, .5f),

AlphaComposite.SrcOver, 
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f),
};

...

Shape redDisc = new Ellipse2D.Float(1, 2, 7, 7);
Shape blueDisc = new Ellipse2D.Float(5, 2, 7, 7);
Rectangle bounds = redDisc.getBounds();
bounds.add(blueDisc.getBounds());

// 
// Iterate through the list of alphaComposites
//
Color red = new Color(200, 50, 50);
Color blue = new Color(50, 50, 120);


int nComposites = alphaComposites.length;
for(int i=0; i<nComposites; i++){
// Set default composite and paint a red square
g.setPaint(red);
g.setComposite(AlphaComposite.SrcOver);
g.fill(redRect);

// Set current composite and blue paint
g.setPaint(blue);
g.setComposite(alphaComposites[i]);
g.fill(blueDisc);

if((i%2)==0)
  g.translate(bounds.width + 10, 0);
else
  g.translate(-bounds.width - 10, bounds.height + 10);