package com.dingcan.view;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.JWindow;
public class StartUp extends JWindow{
ProgressBar pb=null;
public StartUp() {
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setBounds(width/2-200, height/2-125, 400, 250);
pb=new ProgressBar();
Thread proBarThread=new Thread(pb);
proBarThread.start();
this.add(pb);
this.setVisible(true);
}
public static void main(String[] args) {
StartUp su=new StartUp();
}
}
//启动背景JPanel
class ProgressBar extends JPanel implements Runnable{
String[] str={"大","鹏","一","日","同","风","起","扶","摇","直","上","九","万","里"};
int p=0;//画第几个字符游标
int x=20,y=20;//初始paint位置
ZiPos zp=null;
Vector<ZiPos> vecStr=new Vector<ZiPos>();//存放字对象
int probarlen=0;//进度条
int increase=(int) Math.ceil(400/(double)str.length);//每次边长像素
public boolean loadSucess=false;
public ProgressBar() {
this.setBounds(0, 0, 400, 250);
}
public void paintComponent(Graphics g){
Image StartUpBg=null;
try {
StartUpBg=ImageIO.read(new File("images/startUp/index.jpg"));
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
g.drawImage(StartUpBg, 0, 0, this);
//写字
for(int i=0;i<vecStr.size();i++){
ZiPos z=vecStr.get(i);
g.drawString(z.w, z.x, z.y);
}
g.setColor(Color.GREEN);
g.draw3DRect(0, 200, 399, 20, false);
//g.setColor(Color.BLUE);
g.fillRect(1, 201, probarlen, 19);
}
@Override
public void run() {
while(true){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
zp=new ZiPos(str[p],x,y);//创建字对象
repaint();
//存入已画的字对象
vecStr.addElement(zp);
if(this.p==6){//第6个字缓行
this.y=this.y+30;
this.x=40;
}
this.p++;
this.x=this.x+20;
//进度条变长
probarlen+=increase;
if(this.p>str.length-1){
loadSucess=true;
System.exit(0);
break;
}
}
}
}
//字和坐标看成个对象
class ZiPos{
public String w="";
public int x,y;
public ZiPos(String w,int x,int y) {
this.w=w;
this.x=x;
this.y=y;
}
}