Swing 闪屏

来源:互联网 发布:淘宝宝贝详情怎么装修 编辑:程序博客网 时间:2024/04/30 17:42
package testpicturejava; import java.awt.BorderLayout;import java.awt.Dimension; import javax.swing.JFrame;import javax.swing.JPanel;import java.awt.*;import javax.swing.JLabel;import javax.swing.ImageIcon; /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2007</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */public class PictueFrame extends JFrame implements Runnable {    JPanel contentPane;    JLabel jLabel1 = new JLabel();    boolean packFrame = false;    public PictueFrame() {        try {            Thread thre = new Thread(this);            thre.start();        } catch (Exception exception) {            exception.printStackTrace();        }    }     /**     * Component initialization.     *     * @throws java.lang.Exception     */    private void jbInit() throws Exception {     }     public void run() {         contentPane = (JPanel) getContentPane();        contentPane.setLayout(null);        setSize(new Dimension(1024, 768));        setTitle("Frame Title");        this.setUndecorated(true);        this.setResizable(false);         jLabel1.setBounds(new Rectangle(9, 9, 1024, 768));        jLabel1.setIcon(new ImageIcon(PictueFrame.class.getResource(                "sky.jpg")));        contentPane.add(jLabel1);        if (packFrame) {            this.pack();        } else {            this.validate();        }         int height = 300;        int width = 100;        try {            while (true) {                Thread.currentThread().sleep(1);                this.setSize(new Dimension(height, width));                this.setBackground(Color.BLUE);                Dimension screenSize = Toolkit.getDefaultToolkit().                                       getScreenSize();                Dimension frameSize = this.getSize();                if (frameSize.height > screenSize.height) {                    frameSize.height = screenSize.height;                }                if (frameSize.width > screenSize.width) {                    frameSize.width = screenSize.width;                    this.dispose();                    break;                }                this.setLocation((screenSize.width - frameSize.width) / 2,                                 (screenSize.height - frameSize.height) / 2);                this.show();                height = height + 6;                width = width + 10;             }        } catch (HeadlessException ex) {            ex.printStackTrace();        } catch (InterruptedException ex) {            ex.printStackTrace();        }     }} 

原创粉丝点击