制作启动界面

以前写的坦克大战的启动代码。

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);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值