#眉標=Java #副標=Java SE 6.0系列 #大標=Java SE 6.0新功能-歡迎畫面(Splash) #作者=文/黃嘉輝 == 程式1=========== splashFrame = new JFrame(); splashFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); // 建立歡迎畫面 createSplashScreen(); // 顯示歡迎畫面 SwingUtilities.invokeLater(new Runnable() { public void run() { showSplashScreen(); } }); // 載入視窗物件 initializeApplication(); // 延遲 for (long i=0L; i<1000000000L; i++) {} // 隱藏歡迎畫面 SwingUtilities.invokeLater(new Runnable() { public void run() { showApplication(); hideSplashScreen(); } }); ================ == 程式2=========== public static SplashScreen getSplashScreen() { if (GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } System.loadLibrary("splashscreen"); long ptr = _getInstance(); if (ptr==0) { return null; } if (!_isVisible(ptr)) { return null; } return new SplashScreen(ptr); } ================ == 程式3=========== int DoSplashLoadMemory(void* pdata, int size); int DoSplashLoadFile(const char* filename); void DoSplashInit(void); void DoSplashClose(void); void DoSplashSetFileJarName(const char* fileName, const char* jarName); ================ == 程式4=========== try { // 取得SplashScreen物件 java.awt.SplashScreen splashScreen = SplashScreen.getSplashScreen(); if (splashScreen == null) { return; } } catch (Exception ex) {...} ================ == 程式5=========== try { // 建立SplashScreen物件之繪圖Context Graphics2D g2d = splashScreen.createGraphics(); if (g2d == null) { return; } } catch (IllegalStateException isex) {...} ================ == 程式6=========== for(int i=0; i<100; i++) { // 更新SplashScreen物件 splashScreen.update(); try { Thread.sleep(20); } catch(InterruptedException e) {...} } ================ == 程式7=========== splashScreen.close(); ================ == 程式8=========== java SplashDemo ================ == 程式9=========== java -splash:images\Splash.jpg SplashDemo ================ == 程式10=========== Manifest-Version: 1.0 Main-Class: SplashDemo SplashScreen-Image: Splash.jpg ================ == 程式11=========== java -jar SplashDemo.jar ================