制作启动界面

以前写的坦克大战的启动代码。
public class Splash extends JFrame{

	private static final long serialVersionUID = 1L;
	JPanel panel = new JPanel();
	JLabel lblIcon = new JLabel(new ImageIcon("images/boot.jpg"));
	public JProgressBar bar = new JProgressBar();
	public boolean status = true;
	Timer timer = new Timer();
	
	public Splash(){
		init();
	}	
	
	public void init(){		
		this.getContentPane().add(lblIcon,BorderLayout.CENTER);
		this.getContentPane().add(bar,BorderLayout.SOUTH);
		this.bar.setValue(10);
		this.bar.setStringPainted(true);
		bar.setBorderPainted(true);
		this.setTitle("Splash");
		this.setSize(500, 600);	
		//获取屏幕的分辨率大小
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		// 获取标签大小
		Dimension frameSize = this.getPreferredSize();
		// 将欢迎屏幕放在屏幕中间
		setLocation(screenSize.width / 2 - (frameSize.width / 2),screenSize.height / 2 - (frameSize.height / 2));	
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);		
		this.setVisible(true);
		splash();
	}
	
	public void splash(){
		timer.schedule(new TimerTask(){
			public void run(){
				if(bar.getValue()<100){
					bar.setValue(bar.getValue()+6);
					System.out.println("current bar: "+bar.getValue());
				}else{
					timer.cancel();
					setVisible(false);
					new TankFrame();
				}
			}
		},500, 200);			
	}
}

你可能感兴趣的:(timer imageicon)