java7 不规则窗口

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Window;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.MemoryImageSource;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;

import demo.ImageJPanel;

public class TranslucentWindow extends JFrame {
	Image img = null;
	Image img2 = null;
	Image im = null;
	Image im2 = null;
	Image im3 = null;

	ImageFilter imgf = null;

	FilteredImageSource fis = null;
	public TranslucentWindow() {
		super("透明窗体");
		this.setLayout(new FlowLayout());
		this.setBackground(new Color(255,255,255));
//		this.add(new JButton("按钮"));
//		this.add(new JCheckBox("复选按钮"));
//		this.add(new JRadioButton("单选按钮"));
//		this.add(new JProgressBar(20, 100));
		this.setSize(new Dimension(600, 500));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		img = new ImageIcon("e:/123.jpg").getImage();
		
		ImageJPanel imageJP = new ImageJPanel(img);

		imgf = new myImage(100, 100, 100);// 调用自定义类进行对象构造
		fis = new FilteredImageSource(img.getSource(), imgf);// 对图象的源(图象生产者)进行过滤处理,构造出FilteredImageSource对象实例
		img = this.createImage(fis);// 通过FilteredImageSource实例生成Image
//		this.getGraphics().drawImage(img, 0	, 0, this );
		this.add(imageJP);
		this.setSize(imageJP.getWidth(), imageJP.getHeight() + 35);// 这里+35
																	// 是因为JFrame上会有个标题栏
																	// 他会占35像素
//		this.setVisible(true);
	}

	public static void main(String[] args) {
		JFrame.setDefaultLookAndFeelDecorated(true);
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Window w = new TranslucentWindow();
				ImageFilter imf = new ImageFilter();
				
				w.setVisible(true);
				//////////////////////////////
				Point[] points = new Point[]{
                    new Point(100,100),
                    
                    new Point(200,100),
                    new Point(200,200),
                    new Point(100,200),

                    new Point(100,100),
                    
                    new Point(120,120),
                    new Point(180,120),
                    new Point(180,180),
                    new Point(120,180),

                    new Point(120,120),
                    new Point(100,100),

                    new Point(90,210),
                    new Point(210,210),
                    new Point(210,230),
                    new Point(90,230),
                    new Point(90,210),
                    
                    
//                    new Point(80,240),
//                    new Point(220,240),
//                    new Point(220,260),
//                    new Point(80,260),
//                    new Point(80,240),
                    
                    
                    
                };
                Polygon polygon = new Polygon();
                for(int i = 0; i < points.length; i++){
                    polygon.addPoint(points[i].x, points[i].y);
//                    polygon.addPoint(34, 345);
//                    polygon.addPoint(300, 345);
//                    polygon.addPoint(0, 0);
                }
                com.sun.awt.AWTUtilities.setWindowShape(w, polygon);
				//////////////////////////////
				com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.6f);
				
			}
		});
	}

}

你可能感兴趣的:(java,swing,sun,java7)