Add Splash Screen
authorBill Kuker <bkuker@billkuker.com>
Sun, 28 Nov 2010 15:35:59 +0000 (15:35 +0000)
committerBill Kuker <bkuker@billkuker.com>
Sun, 28 Nov 2010 15:35:59 +0000 (15:35 +0000)
gui/MotorSim.java
gui/SplashWindow3.java [new file with mode: 0644]
gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorWorkbench.java
gui/splash.png [new file with mode: 0644]

index 6f1a07f5318f1663fd7a0057316192d429b59832..3352311b7aaaca0dbe0a32d402a6cc7d682613b8 100644 (file)
@@ -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 (file)
index 0000000..86a8a85
--- /dev/null
@@ -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);
+       }
+}
index 098cf88335bd0a51b5562c2a2be6398eb5d27fa1..c2c40312f8163225fb0681a1dceef1160c998cd2 100644 (file)
@@ -57,7 +57,7 @@ public class MotorWorkbench extends RememberJFrame {
 \r
 \r
                setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);\r
-               setVisible(true);\r
+               //setVisible(true);\r
 \r
        }\r
 \r
diff --git a/gui/splash.png b/gui/splash.png
new file mode 100644 (file)
index 0000000..3e627da
Binary files /dev/null and b/gui/splash.png differ