Here you can find the source of clear(Image img)
public static void clear(Image img)
//package com.java2s; //License from project: LGPL import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; public class Main { public static void clear(Image img) { Graphics g = img.getGraphics(); try {// w w w. j a va2 s.c om if ((g instanceof Graphics2D)) { ((Graphics2D) g).setComposite(AlphaComposite.Clear); } else { g.setColor(new Color(0, 0, 0, 0)); } g.fillRect(0, 0, img.getWidth(null), img.getHeight(null)); } finally { g.dispose(); } } }