Here you can find the source of showSplash(ImageIcon image, int milliseconds)
public static void showSplash(ImageIcon image, int milliseconds)
//package com.java2s; /*//from w ww .j a v a 2s . c o m File: WindowUtilities.java Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org) The Cytoscape Consortium is: - Institute for Systems Biology - University of California San Diego - Memorial Sloan-Kettering Cancer Center - Institut Pasteur - Agilent Technologies This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder is on an "as is" basis, and the Institute for Systems Biology and the Whitehead Institute have no obligations to provide maintenance, support, updates, enhancements or modifications. In no event shall the Institute for Systems Biology and the Whitehead Institute be liable to any party for direct, indirect, special, incidental or consequential damages, including lost profits, arising out of the use of this software and its documentation, even if the Institute for Systems Biology and the Whitehead Institute have been advised of the possibility of such damage. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ import java.awt.Window; import java.awt.Insets; import java.awt.Dimension; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import javax.swing.JWindow; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.ImageIcon; public class Main { protected static JWindow splashWindow = null; protected static JComponent splashContent = null; public static void showSplash(ImageIcon image, int milliseconds) { showSplash(image, milliseconds, true); } public static void showSplash(ImageIcon image, int milliseconds, boolean start_timer) { showSplash(new JLabel(image), milliseconds, start_timer); } public static void showSplash(JComponent content, int milliseconds) { showSplash(content, milliseconds, true); } public static void showSplash(JComponent content, int milliseconds, boolean start_timer) { hideSplash(); if (splashWindow == null) { splashWindow = new JWindow(); } splashContent = content; splashWindow.getContentPane().add(splashContent); splashWindow.pack(); centerWindowLocation(splashWindow); splashWindow.setVisible(true); splashContent.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { hideSplash(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); // if( splashTimer == null ) { // splashTimer = new javax.swing.Timer ( // milliseconds, // new ActionListener () { // public void actionPerformed ( ActionEvent event ) { // WindowUtilities.hideSplash(); // } // } // ); // splashTimer.setRepeats( false ); // } else { // splashTimer.setDelay( milliseconds ); // } // if( start_timer ) { // splashTimer.start(); // } } public static void hideSplash() { // if( ( splashTimer != null ) && splashTimer.isRunning() ) { // splashTimer.stop(); // } if ((splashWindow != null) && splashWindow.isVisible()) { splashWindow.setVisible(false); if (splashContent != null) { splashWindow.getContentPane().remove(splashContent); splashContent = null; } } } public static void centerWindowLocation(Window window) { Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); GraphicsConfiguration configuration = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Insets screen_insets = Toolkit.getDefaultToolkit().getScreenInsets( configuration); screen_size.width -= screen_insets.left; screen_size.width -= screen_insets.right; screen_size.height -= screen_insets.top; screen_size.height -= screen_insets.bottom; Dimension frame_size = window.getSize(); window.setLocation( ((screen_size.width / 2) - (frame_size.width / 2)) + screen_insets.left, ((screen_size.height / 2) - (frame_size.height / 2)) + screen_insets.top); } }