473,503 Members | 10,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splash Screen before program begins

37 New Member
Hey everyone!
I've been trying to create a Splash Screen in my Java program. I've managed to make the splash screen show itself, with the program. I now want to make it show first, and then show my main program. As in every program nowadays..

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  
  3.  
  4. package ****;
  5.  
  6. import java.awt.BorderLayout;
  7. import java.awt.Dimension;
  8. import java.awt.Frame;
  9. import java.awt.Toolkit;
  10. import java.awt.event.MouseAdapter;
  11. import java.awt.event.MouseEvent;
  12. import javax.swing.ImageIcon;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JWindow;
  16. import javax.swing.SwingUtilities;
  17.  
  18.  
  19. class SplashWindow1 extends JWindow
  20. {
  21.  
  22.  
  23.     public SplashWindow1(String filename, Frame f,int waitTime)
  24.     {
  25.         super(f);
  26.         JLabel l = new JLabel(new ImageIcon(filename));
  27.         getContentPane().add(l, BorderLayout.CENTER);
  28.         pack();
  29.         Dimension screenSize =
  30.           Toolkit.getDefaultToolkit().getScreenSize();
  31.         Dimension labelSize = l.getPreferredSize();
  32.         setLocation(screenSize.width/2 - (labelSize.width/2),
  33.                     screenSize.height/2 - (labelSize.height/2));
  34.         addMouseListener(new MouseAdapter()
  35.             {
  36.                 public void mousePressed(MouseEvent e)
  37.                 {
  38.                     setVisible(false);
  39.                     dispose();
  40.                 }
  41.             });
  42.         final int pause = waitTime;
  43.         final Runnable closerRunner = new Runnable()
  44.             {
  45.                 public void run()
  46.                 {
  47.                     setVisible(false);
  48.                     dispose();
  49.                 }
  50.             };
  51.         Runnable waitRunner = new Runnable()
  52.             {
  53.                 public void run()
  54.                 {
  55.                     try
  56.                         {
  57.                             Thread.sleep(pause);
  58.                             SwingUtilities.invokeAndWait(closerRunner);
  59.                         }
  60.                     catch(Exception e)
  61.                         {
  62.                             e.printStackTrace();
  63.                             // can catch InvocationTargetException
  64.                             // can catch InterruptedException
  65.                         }
  66.                 }
  67.             };
  68.  
  69.         setVisible(true);
  70.         Thread splashThread = new Thread(waitRunner, "SplashThread");
  71.         splashThread.start();
  72.     }
  73. }
and in the Main class I call the SplashScreen like this:

Expand|Select|Wrap|Line Numbers
  1. JFrame myframe = new Main();
  2. SplashWindow1 a = new SplashWindow1("C:/*********/splash.gif",myframe,4000);
  3.  
With this code it runs with the program, so the splash screen shows and myframe is visible too and I can start working.

I want the splash screen to show first, load stuff etc. and then show myframe!

I thought things like

Expand|Select|Wrap|Line Numbers
  1. Frame f=new JFrame();
  2.                     SplashWindow1 a = new SplashWindow1("C:/*****/splash.gif",f,4000);
  3.                     while(a.isVisible()) try {
  4.                         Thread.sleep(100);
  5.                     } catch (InterruptedException ex) {
  6.                         Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  7.                     }
but it doesn't work, the JWindow of the splash screen is like stuck, and after the 4 seconds my main program shows.


Any ideas??

Thanks in advance!
Alex
Jan 8 '11 #1
0 1269

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2415
by: Ryan | last post by:
Hello, I have a c++ application and I would like to simply play a short video clip (mpg file) as a splash screen when the application first begins to execute. I seem to be having trouble so far. ...
11
1569
by: K E Senthil Kumar | last post by:
Hi, I have created an application which uses a SQL server database. I created a mainform which retreives all the customers. This takes about 3sec. I have created a splash screen too. I use a...
3
319
by: Rui Dias | last post by:
Hello, I'm starting to program in Visual Studio 2005 and I noticed that there is a property to set the application splash screen. However it seems to me that this property is quite limitative....
1
2237
by: Ken Allen | last post by:
I am developing a small utility program that must perform a considerable amount of 'background' or 'research' work before it can display any user interface. In general it can take 3-15 seconds to...
1
1187
by: steve | last post by:
Hi All I want to display a splash screen when my windows application loads, to show sql server connection progress etc. First though I want to run some code to check for a valid program...
5
6385
by: steve | last post by:
Hi All I have a form set as the splash screen in VB.net 2005 application properties How can I tell when it has or is closing, as I want to then run some licence checking code without the...
0
971
by: fedrok | last post by:
Hi to you all. I'm developing a Windows form program in VB.NET and Visual Studio 2005. Vs2005 contains a model for splash screen. I added one in my solution and all works good. Buyt now: ...
7
1837
by: giddy | last post by:
hi , like my subject says . . i wanna make a splash screen , i have the picture i want to use. I wanna do it the right way , in VB i'd seen source that used a FORM! without borders and a...
2
4192
by: will_456 | last post by:
In vb2005 Express: In My Project Application Splash Screen I have selected my splash screen form. The form opens on project startup but closes immediately before anyone would have time to read...
1
1489
by: Mark B | last post by:
Hi experts, My program takes around 20 seconds to load. (VB 2008 on Vista & .Net 3.5) Of course, during that time, it'd be nice to have a splash screen, but not something boring. What are...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.