Source Code : Creating a varying gradient translucent window

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Creating a varying gradient translucent window

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.GraphicsEnvironment;
import java.awt.Paint;

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

public class Test {

  public static void main(String[] args) {
    GraphicsEnvironment envmt = GraphicsEnvironment
        .getLocalGraphicsEnvironment();
    GraphicsDevice device = envmt.getDefaultScreenDevice();

    if (!device
        .isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
      System.out
          .println("Translucent windows are not supported on your system.");
      System.exit(0);
    }
    JFrame.setDefaultLookAndFeelDecorated(true);
    ApplicationWindow window = new ApplicationWindow();
    window.setVisible(true);
  }
}

class ApplicationWindow extends JFrame {

  public ApplicationWindow() {
    setBackground(new Color(0, 0, 0, 0));
    this.setSize(200, 200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel() {
      @Override
      protected void paintComponent(Graphics gradient) {
        if (gradient instanceof Graphics2D) {
          final int Red = 150;
          final int Green = 150;
          final int Blue = 150;
          Paint paint = new GradientPaint(0.0f, 0.0f, new Color(Red, Green,
              Blue, 0), getWidth(), getHeight(), new Color(Red, Green, Blue,
              255));
          Graphics2D gradient2d = (Graphics2D) gradient;
          gradient2d.setPaint(paint);
          gradient2d.fillRect(0, 0, getWidth(), getHeight());
        }
      }
    };
    this.setContentPane(panel);
  }
}

 

Thank with us