Sunday, August 12, 2012

Creating a REAL Splash Screen in Java using NetBeans IDE

Two weeks earlier, I posted an article on how to Create a Splash Screen in Java using NetBeans IDE that showed how to convert a animated gif into a splash screen for your java app. But some readers asked that it was not what they were looking and they want to learn how to create a real splash screen and I think by real they meant showing a progress bar while they load some resources in the background (make their app ready to use). So here I am with the video tutorial for the same.


Although, I made two part long video tutorial but still it wasn't enough to demonstrate all things I wanted. So, here are some more tips that I would like to share in a question and answer form.

Q The progress bar only fills to half (even in the video).
A Sorry, my fault! It was because I looped it only for 5 times. The progress must be relative to how much time you are looping. So to correct, either you can loop it 5 more times i.e 10 or you can change this statement -
int doneProg = prog*width/50;
I have corrected it in the final project.

Q How can I change the font for the text in loadingTextArea?
A Create a new font variable -
public static Font myfont;
Now in the loadingMethod() below the line: loadingGraphics = loadingScreen.createGraphics(); do the following:
myfont = new Font("TimesRoman", Font.BOLD, 14);
loadingGraphics.setFont(myfont);
Q How can I place my progressArea at the right side of the image base-aligned with my textArea?
A Just change the placement for loadingProgressArea in the loadingMethod() to:
loadingProgressArea = new Rectangle2D.Double(wd*0.55, ht*0.7, wd*0.4, 25);
Q The splash screen is automatically centered, but my form opens in the top left corner. How can I make my form open in the center of the screen?
A Right Click your form>Events>windowOpened and paste the following code-
this.setLocationRelativeTo(null);
Q The doneProgress doesn't cover the whole of progressArea, it seems a pixel above the bottom edge. How can I correct this?
A Replace the fillRect() line in the loadingProgress() method with this:
loadingGraphics.fillRect(x, y+1, doneProg, height);
You can download the whole Netbeans project from here.


If you have any other query you can comment and I would just expand this Q/A list.

Don't forget sharing is caring!!

10 comments:

  1. Instead of image can i add a JFrame form as a splash screen..? is it posble..? plz reply...

    ReplyDelete
  2. in splash screen,if i want to use it before any program,then what would be the change in manifest file? and how can we add other files in manifest?????

    ReplyDelete
  3. How can I insert a splash screen in a ready-made program? I'll very much appreciate your reply

    ReplyDelete
  4. Is the author still active here?i have few questions...

    ReplyDelete
  5. my gif doesnt work if i remove this line, please help me. The gif image is the background


    try{
    URL url = new URL("https://sites.google.com/site/rohanthepcwizard/games/temp.txt");

    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

    String str;
    while((str = in.readLine()) !=null){
    System.out.println(str);
    }
    in.close();
    }
    catch(MalformedURLException e){
    }
    catch(IOException e){
    }

    ReplyDelete
    Replies
    1. If you remove that line then your method have nothing to process. Your splash screen ends within a few milliseconds and that's why you're not able to see it.
      Judging by your situation, this would be a better article to follow ; http://www.thepcwizard.in/2012/07/creating-splash-screen-in-java-using.html

      Delete
  6. its not working if i clean and build main project

    ReplyDelete
  7. thanks frnd.... its really helpfull. :)

    ReplyDelete