⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splashscreen.java

📁 dump3 morpheus 0.2.9 src
💻 JAVA
字号:
package net.za.grasser.duplicate;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;

/**
 * This class displays a splash screen for a given period.<br>
 * Nabbed from <a href="http://www.java-tips.org/java-se-tips/javax.swing/how-to-implement-a-splash-screen-for-an-application.html">How to implement a splash
 * screen for an application</a>
 * 
 * @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
 * @version $Revision:$
 */
public class SplashScreen extends JWindow {
  /**
   * <code>serialVersionUID</code> long -
   */
  private static final long serialVersionUID = 6124882603956758641L;
  /**
   * <code>duration</code> SplashScreen -
   */
  private int duration;

  /**
   * Constructor
   * 
   * @param d duration in milliseconds.
   */
  public SplashScreen(final int d) {
    duration = d;
  }

  /**
   * A simple little method to show a title screen in the center of the screen for the amount of time given in the constructor
   */
  public void showSplash() {
    final JPanel content = (JPanel)getContentPane();
    content.setBackground(Color.white);
    // Set the window's bounds, centering the window
    final int width = 350;
    final int height = 146;
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    final int x = (screen.width - width) / 2;
    final int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);
    // Build the splash screen
    final JLabel label = new JLabel(new ImageIcon("icons/splash.gif"));
    final JLabel copyrt = new JLabel("Copyright 2004, Alexander Grasser", SwingConstants.CENTER);
    copyrt.setFont(new Font("Arial", Font.BOLD, 12));
    content.add(label, BorderLayout.CENTER);
    content.add(copyrt, BorderLayout.SOUTH);
    content.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, new Color(152, 216, 250, 255), new Color(102, 137, 214, 255)));
    final int pause = duration;
    final Runnable closerRunner = new Runnable() {
      public void run() {
        setVisible(false);
        dispose();
      }
    };
    Runnable waitRunner = new Runnable() {
      public void run() {
        try {
          Thread.sleep(pause);
          SwingUtilities.invokeAndWait(closerRunner);
        } catch (Exception e) {
          e.printStackTrace();
          // can catch InvocationTargetException
          // can catch InterruptedException
        }
      }
    };
    setVisible(true);
    if (duration > 0) {
      Thread splashThread = new Thread(waitRunner, "SplashThread");
      splashThread.start();
    }
  }

  /**
   * This method hides the splash screen
   */
  public void hideSplash() {
    setVisible(false);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -