From: Bill Kuker Date: Sun, 28 Nov 2010 15:35:59 +0000 (+0000) Subject: Add Splash Screen X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=502aa60e6d31f909520ab1a53e83080eb27b064b;hp=ae499b0c7a517c280058d5851c36a63c9b26ccf5;p=sw%2Fmotorsim Add Splash Screen --- diff --git a/gui/MotorSim.java b/gui/MotorSim.java index 6f1a07f..3352311 100644 --- a/gui/MotorSim.java +++ b/gui/MotorSim.java @@ -1,6 +1,8 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; +import com.billkuker.rocketry.motorsim.visual.workbench.MotorWorkbench; + public class MotorSim { public static void main(String args[]) throws Exception { @@ -14,13 +16,17 @@ public class MotorSim { } catch (Exception e1) { e1.printStackTrace(); } + SplashWindow3 sw = new SplashWindow3("splash.png",null, 4000); + final MotorWorkbench mw = new com.billkuker.rocketry.motorsim.visual.workbench.MotorWorkbench(); + Thread.sleep(4000); SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { - new com.billkuker.rocketry.motorsim.visual.workbench.MotorWorkbench().setVisible(true); + mw.setVisible(true); } }); + } } diff --git a/gui/SplashWindow3.java b/gui/SplashWindow3.java new file mode 100644 index 0000000..86a8a85 --- /dev/null +++ b/gui/SplashWindow3.java @@ -0,0 +1,55 @@ +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JWindow; +import javax.swing.SwingUtilities; +class SplashWindow3 extends JWindow { + public SplashWindow3(String resName, Frame f, int waitTime) { + super(f); + JLabel l = new JLabel(new ImageIcon(this.getClass().getResource(resName))); + getContentPane().add(l, BorderLayout.CENTER); + pack(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension labelSize = l.getPreferredSize(); + setLocation(screenSize.width / 2 - (labelSize.width / 2), screenSize.height / 2 - (labelSize.height / 2)); + addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + setVisible(false); + dispose(); + } + }); + final int pause = waitTime; + 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); + Thread splashThread = new Thread(waitRunner, "SplashThread"); + splashThread.start(); + } + + + public static void main(String args[]) { + SplashWindow3 sw = new SplashWindow3("splash.png",null, 4000); + } +} diff --git a/gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorWorkbench.java b/gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorWorkbench.java index 098cf88..c2c4031 100644 --- a/gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorWorkbench.java +++ b/gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorWorkbench.java @@ -57,7 +57,7 @@ public class MotorWorkbench extends RememberJFrame { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); + //setVisible(true); } diff --git a/gui/splash.png b/gui/splash.png new file mode 100644 index 0000000..3e627da Binary files /dev/null and b/gui/splash.png differ