public static Image setSemiTransparency(Image srcImg, double semiTrans) // method accepts a transparent color.
    // It'll transform all pixels of the transparent color to transparent.
    {
        if (semiTrans > 1.0)
            semiTrans = 1.0;
        if (semiTrans < 0.0)
            semiTrans = 0.0;
        final int alpha = (int) (255 * (1.0 - semiTrans));

        ImageFilter filter = new RGBImageFilter() // overriding part of the RGBImageFilterClass to produce a specialized filter.
        {
            public int filterRGB(int x, int y, int rgb) // overriden method
            {
                if ((rgb & 0xFF000000) != 0)
                    return (rgb & 0x00FFFFFF) | (alpha << 24); // alpha bits set to 0 yields transparency.
                else
                    return rgb;
            }
        };

        ImageProducer ip = new FilteredImageSource(srcImg.getSource(), filter);
        Toolkit tk = Toolkit.getDefaultToolkit();
        tk.sync();
        Image result = tk.createImage(ip);


        return result;
    }