欢迎来到天天文库
浏览记录
ID:44811692
大小:73.51 KB
页数:3页
时间:2019-10-29
《JSplashWindow,软件启动界面的编写》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、JSplashWindow,软件启动界面的编写运行如下:(鼠标放置此处会显示等待状态)15秒后如下:代码如下:packagejsplashWindow;importjava.awt.BorderLayout;importjava.awt.Cursor;importjava.awt.Dimension;importjava.awt.Toolkit;importjava.net.URL;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.s
2、wing.JLabel;importjavax.swing.JPanel;importjavax.swing.JWindow;publicclassJSplashWindowextendsJWindowimplementsRunnable{privatestaticfinallongserialVersionUID=1L;ThreadsplashThread=null;publicJSplashWindow(){setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CU
3、RSOR));JPanelsplash=newJPanel(newBorderLayout());URLurl=getClass().getResource("图片.jpg");if(url!=null){System.out.println("------");splash.add(newJLabel(newImageIcon(url)),BorderLayout.CENTER);}setContentPane(splash);Dimensionscreen=getToolkit().getScreenSize
4、();pack();setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2);}publicvoidrun(){try{setVisible(true);Thread.sleep(15000);}catch(Exceptionex){ex.printStackTrace();}this.dispose();}publicvoidstart(){this.toFront();splashThread=newThr
5、ead(this);splashThread.start();}staticvoidshowFrame(Stringtitle){JFrameframe=newJFrame(title);frame.setSize(400,300);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();DimensionframeSize=frame.
6、getSize();if(frameSize.height>screenSize.height){frameSize.height=screenSize.height;}if(frameSize.width>screenSize.width){frameSize.width=screenSize.width;}frame.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);frame.se
7、tVisible(true);}publicstaticvoidmain(String[]args){showFrame("Demosplashwindow");JSplashWindowsplash=newJSplashWindow();splash.start();}}
此文档下载收益归作者所有