Home Java Example Java Swing Graphics2D Use Alpha values to draw in Layers

Related Tutorials


 
 

Share on Google+Share on Google+

Use Alpha values to draw in Layers

Advertisement
In this section, you will studied how to use alpha values to the draw the specific shape in layers.

Use Alpha values to draw in Layers

     

In this section, you will studied how to use alpha values to the draw the specific shape in layers.

An alpha object produces the alpha value which changes with time specified by the parameters of the alpha object. The alpha value is the graphics state parameter that is used to composite objects to the existing page. At full intensity, objects are opaque. At zero intensity, objects are invisible. As the intensity decreases, the specific shape becomes transparent. It can be a part of vertex or texture. 
We are providing you an example which uses the alpha values to show transparency. A frame of size (350,300) is created. The g.fillOval() fills the oval shape with the color defined in the constructor new Color(150, 100, 100, 70) of class Color. The values defined in the constructor are alpha values which shows the transparency.

Here is the code of UseAlphaValues.java

import java.awt.*;
import javax.swing.*;

public class UseAlphaValues extends JFrame {
int width, height;

  UseAlphaValues(String st) {
  this(st, 350300);
  }
  UseAlphaValues(String st, int w, int h) {
  setTitle(st);
  setSize(width = w, height = h); 
  setBackground(Color.black);
  }
 public void paint(Graphics g) {
  Color color1 = new Color(15010010070); 
  Color color2 = new Color(75150200125);
  Color color3 = new Color(120150200200);
  g.setColor(color1);
  g.fillOval(00, width / 2, height / 2);
  g.setColor(color2);
  g.fillOval(width / 4, height / 4, width / 2, height / 2);
  g.setColor(color3);
  g.fillOval(width / 3, height / 3, width / 4, height / 4);
  }
  public static void main(String[] args) {
  new UseAlphaValues("Use Alpha values to draw in layers.")
  .setVisible(
true);
  }
}

Output will be displayed as:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 1, 2008

Related Tutorials

Discuss: Use Alpha values to draw in Layers  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com