
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.GrayFilter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GrayFilterDemo extends JFrame {
/**
* 一个图像过滤器,它通过将图像转换成灰度级图像并增亮图像中的像素来“禁用”图像。
* 按钮可使用该过滤器为禁用的按钮创建一个图像。
*/
public GrayFilterDemo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
ImageIcon icon = new ImageIcon("E:\\java\\Test\\icon\\44.png");
JButton b1 = new JButton("Regular", icon);
p.add(b1);
//构造一个 GrayFilter 对象,该对象将彩色图像过滤成灰度级图像
Image image = GrayFilter.createDisabledImage(icon.getImage());
JButton b2 = new JButton("GrayFilter", new ImageIcon(image));
p.add(b2);
getContentPane().add(p);
pack();
setVisible(true);
}
public static void main(String arg[]) {
new GrayFilterDemo();
}
}