起動画面の作成

1585 ワード

以前書いた戦車大戦の起動コード.

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);			
	}
}