Java实现窗口慢慢变大

来源:互联网 发布:怎么删除淘宝上的好评 编辑:程序博客网 时间:2024/05/02 00:46
package Rong;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Demo extends JFrame implements Runnable {
 
 private static final long serialVersionUID =1L;
 private int width = 0;
 private int height = 0;
 ImageIcon bg= newImageIcon("D:/1.jpg");//背景图片
 JPanel panel=new JPanel();
 JLabel label=new JLabel(bg);
 public Demo() {
  this.setUndecorated(true);//无标题栏
  this.setSize(0, 0);//初始大小
  this.setLocation(400, 250);//窗口位置
  this.getContentPane().add(label);
 this.getContentPane().setBackground(Color.BLACK);
  Imageimg=Toolkit.getDefaultToolkit().getImage("D:/star.png");
    this.setIconImage(img);//图标
  this.setVisible(true);//设置可见
 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//默认关闭方式
 }

 public static void main(String[] args) {
  Demo demo = new Demo();
  new Thread(demo).start();
 }
 //窗口慢慢变大
 public void run() {
  while (this.width < 300) {
   width++;
   height++;
   this.setSize(width,height);
   repaint();
   try {
   Thread.sleep(20);
   } catch (InterruptedExceptione) {
   e.printStackTrace();
   }
  }
 }
}