3

I'm using NetBeans IDE 6.8 (Mac Version). which tool of their GUI builder will assist me in doing this?

What I want is is to show the user an image while my application is loading for couple of seconds before I show him the application. How can I do that? initializing

M. A. Kishawy
  • 5,001
  • 11
  • 47
  • 72

4 Answers4

9

If you have Java 6 installed, checkout the Splash-Screen tutorial.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
5

actually, you can do that by using the -splash flag in the java program... for example, you want to show the image splash.jpg when you run main.class,

so what you will do is,

java -splash:pathoftheimage/splash.jpg main

ultrajohn
  • 2,527
  • 4
  • 31
  • 56
3

As you're running on a MAC you probably won't have access to Java 6 and so will have to build the splashscreen yourself. You should run code similar to the following early in your initialisation cycle (i.e. so that the splashscreen dialog is displayed for the maximum amount of time).

JDialog dlg = new JDialog();
// Remove dialog decorations to make it look like a splashscreen.
dlg.setUndecorated(true);
dlg.setModal(true);
dlg.setLayout(new BorderLayout());
// Load image.
ImageIcon img = new ImageIcon(getClass().getResource("/foo/bar/splash.png");
// Add image to center of dialog.
dlg.add(img, BorderLayout.CENTER);
dlg.setLocationRelativeTo(null);
dlg.setVisible(true);

// ... Perform application initialisation here.

// Initialisation complete so hide dialog.
dlg.setVisible(false);
dlg = null;
Adamski
  • 54,009
  • 15
  • 113
  • 152
  • 2
    Mac OS X does have Java 6 available since 10.5. – Joachim Sauer Feb 10 '10 at 08:04
  • What library should I import for the following class: BorderLayout(); ImageIcon(); – M. A. Kishawy Feb 10 '10 at 08:46
  • 1
    You'll need to import java.awt.* and javax.swing.* although if you're using a good IDE it should perform auto-imports. If not, you could use the JDK online docs to determine the packages to import: http://java.sun.com/javase/6/docs/api/ – Adamski Feb 10 '10 at 08:59
  • 1
    @Joachim: I did not know that. @MAK: Given Joachim's response you should definitely try the "-splash" route first as it involves no code changes. – Adamski Feb 10 '10 at 09:00
  • well...i got exceptio error >> javax.swing.ImageIcon.(ImageIcon.java:138) – M. A. Kishawy Feb 10 '10 at 09:15
  • @MAK: It's likely that your image isn't available (i.e. the image file isn't saved in the correct place). Remember, the resource is based on the app's classpath. If you're running your app from a jar or a "classes" directory created by your IDE then check the image file is actually in the jar or relevant directory. Without more information on the error that's the best I can suggest I'm afraid. – Adamski Feb 10 '10 at 09:35
-1

If you are using NetBeans... then don't worry NetBeans has solved this problem for you.

  1. Right Click On your Project after opening it.
  2. Go to properties
  3. Click Application
  4. There will be Splash Screen, Browse your image which you want to show.

As shown in Pictures below

enter image description here

enter image description here

When you will do this , your image will show but you will not be able to see this. To See it, you have to delay time of appearence of next window. For this do these steps.

  1. Go to your JFrame code area which you want to show next.
  2. In Main Fun there will be run fun.
  3. Inside run function just write the following code.

    try{

    Thread.sleep(time in milisecond just like 4200);

    //Create Next Frame Object Here }

    catch(Exception ex) { }

  • Please don't use `inline code markup` for anything *but* actual inline code. Almost every use of it in this entire post is wrong. (Yes, even the parts that are code — indent the block once more to get a code block as you should have.) – Nathan Tuggy Aug 04 '17 at 04:44