?? startupview.java~18~
字號(hào):
package com.ui.util;import javax.swing.*;import java.awt.*;import java.net.*;/** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2008</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */public class StartupView extends JWindow implements Runnable{ private boolean needToShow = true; private Thread thread; public StartupView() { JPanel splash = new JPanel(new BorderLayout()); URL url = getClass().getResource("1.jpg"); //獲得指定資源文件的絕對(duì)路徑。 if (url != null) { splash.add(new JLabel(new ImageIcon(url)), BorderLayout.CENTER); } else { System.out.println("url is null"); } setContentPane(splash); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); //獲得屏幕的大小 pack(); setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2); //使啟動(dòng)窗口居中顯示 toFront(); //window類(lèi)的toFront()方法可以讓啟動(dòng)界面顯示的時(shí)候暫時(shí)在最前面,用window類(lèi)的setAlwayOnTop(boolean)方法可以讓窗口總保持在最前面。 setAlwaysOnTop(true); } public void run() { try { setVisible(true); //Thread.sleep(2000); while (this.needToShow) { System.out.print(". "); Thread.sleep(1000); } } catch (Exception e) { e.printStackTrace(); } dispose(); } public void startup() { this.thread = new Thread(this); this.thread.start(); } public void exit() { this.needToShow = false; }}/*getToolkit()方法是java.awt.window類(lèi)的方法它可以得到一個(gè)Toolkit類(lèi)。Toolkit對(duì)象的getScreenSize()方法可以得到屏幕的大小。 getScreenSize()方法返回一個(gè) Dimension對(duì)象,它的width,height屬性就是屏幕的寬和高。 Object getClass()方法是java.lang.Object類(lèi)的方法它可以獲得當(dāng)前正在運(yùn)行類(lèi)的對(duì)象 URL getResource(String name)方法是java.lang.Class類(lèi)的方法用此方法可以獲得一個(gè)指定資源文件的絕對(duì)路徑。*/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -