当前位置:天才代写 > tutorial > JAVA 教程 > Java Application启动画面的建造

Java Application启动画面的建造

2017-11-11 08:00 星期六 所属: JAVA 教程 浏览:344

现象:

JBuilder启动时有一个启动画面,在Jbuilder所有的初始化事情都完成之后,启动画面消失,继而JBuilder可以开始利用。

办理方案:

该方案基于我所做过的一个项目。

1、新建一个启动画面Window类

java.awt.Window windowSplash;

2、挪用prepareSplash()函数,初始化启动界面

private void prepareSplash()
  {
     Toolkit toolkit = Toolkit.getDefaultToolkit();
     windowSplash = new Window( this );
     Image image = toolkit.getImage( "images" + File.separator + "splash.gif" );
     ImageCanvas canvas = new ImageCanvas( image );
     windowSplash.add( canvas, "Center" );
     Dimension scmSize = toolkit.getScreenSize();
     int imgWidth = image.getWidth( this );
     int imgHeight = image.getHeight( this );
     windowSplash.setLocation( scmSize.width/2 - (imgWidth/2), scmSize.height/2 - (imgHeight/2) );
    windowSplash.setSize( imgWidth, imgHeight );
   }

3、在Application的JFrame类(主界面)中挪用startSplash(),显示启动界面,然后初试化JFrame的各个可视化组件,初始化靠山数据库等(如数据库的毗连)

private void startSplash()
   {
     windowSplash.setVisible( true );
    windowSplash.toFront();
   }

4、在所有的初始化事情完成之后,挪用stopSplash()函数,遏制显示启动画面

private void stopSplash()
{
    windowSplash.dispose();
  }

 

    关键字:

天才代写-代写联系方式