Monday, November 18, 2013

Splash Screen

Splash screen is a special window that displays in a short time period before the main window of a program or website shows. Generally, on the splash screen, you will see an image that represents an introduction to the program or website. Sometimes, a splash screen displays a progress bar to inform the user about a process that is loading and might take a long time to complete. When the process completes, the splash screen disappears.

In Java, you can use the SplashScreen class (in awt package) to create a splash screen for your program. Alternatively, you can write your own code to create a splash screen. In this tutorial, i prefer to do the latter. First of all, you will have a class that extends the JFrame class. This class will represent the splash screen. In this tutorial, i name it as SimpleSplashScreen. The splash screen has no border and title. So will use the setUndecorated method to hide border and title. On the splash screen, there is an image that provides introductory information of the program. The JLabel component is used to wrap the image. Then it will be added on the splash screen to show the image. In the SimpleSplashScreen class, you need to add two methods. The first method (wait) allows the user to set the time delay of the splash screen. Another method (showScreen) will be invoked in the program to display the splash screen. Simply, when the time is out, the splash screen disappears and the Welcome window is shown.

splash screen

welcome


This is the complete code of the SplashScreen program.

import java.awt.Container;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

class SimpleSplashScreen extends JFrame{
int delay=2000; //default delay time 2 seconds
SimpleSplashScreen(String imgfile){
ImageIcon iicon=new ImageIcon(imgfile);
int iwidth=iicon.getIconWidth();
int iheight=iicon.getIconHeight();
setSize(iwidth,iheight);
setLocationRelativeTo(null);
setUndecorated(true);
Container cont=getContentPane();
JLabel lbl=new JLabel();
lbl.setIcon(iicon);
cont.add(lbl);
}
//set time delay
public void wait(int mills){
delay=mills;
}

public void showScreen(){
setVisible(true); //show the screen
try {
Thread.sleep(delay); //delay the screen
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//close the SplashScreen when time out
dispose();
new MaiInterface();
}
}

class MaiInterface extends JFrame{
MaiInterface(){
setSize(400,300);
setTitle("Your main interface here");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cont=getContentPane();
JLabel lbl=new JLabel("Welcome");
lbl.setHorizontalAlignment(JLabel.CENTER);
lbl.setFont(new Font("Arial", Font.BOLD,30));
cont.add(lbl);
setVisible(true);
}
}
public class SplashSr {
public static void main(String[] args){
SimpleSplashScreen sss=new SimpleSplashScreen("d:/splashscreen.png");
sss.wait(5000);
sss.showScreen();
}
}

compass app flashLight app

110 comments:

  1. Jave website such as this one really rocks! Sharing your knowledge to other people is really inspiring, because not all are java programmers, but anyone can learn the basics. Students from http://bestessay.education/making-reaction-papers are really taking advantage of your post most of the time.

    ReplyDelete
  2. Java is programming language which is used in almost all the applications and games which are on the web. Java is being used extensively and it will be used extensively in near future. So getting trained in Java will surely be helpful.
    Thanks,
    Java Training in Chennai | Java courses in Chennai | Java Training Institutes in Chennai

    ReplyDelete
  3. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Hadoop Training Chennai|Big Data Training Chennai|Best Hadoop Training in Chennai

    ReplyDelete
  4. It's really good to know that these java codings are still being used as reference of present and future java codes. Glad I was able to learn more here on how splash screen coding works.

    ReplyDelete
  5. The blog gave me idea about splash screen Thanks for sharing it
    Hadoop Training in Chennai

    ReplyDelete
  6. really you have been shared very informative blog. it will be helpful to the peoples who are all working under the technology. so keep on sharing such kind of an interesting blog.
    hadoop training in chennai

    ReplyDelete
  7. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. before i read this blog i didn't have any knowledge about this. but now i got some knowledge.
    java training in chennai

    ReplyDelete
  8. Hi admin..,
    First of i appreciate your coding knowledge. This is very nice. Iam really happy to command your blog because this is one of the nice blog for me. I gather lot of information from this blog.
    Thanks for sharing.


    Core Java Online Training

    ReplyDelete
  9. The information shared are very much useful My sincere Thanks for sharing this post please continue to share this post
    Java Training in Chennai

    ReplyDelete
  10. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...Want to build your website.
    White Label Website Builder

    ReplyDelete
  11. Your details are very informative for me. I am interested to learn AngularJS Training in Chennai or AngularJS course in Chennai Do you have this kind of post means kindly share with me.

    ReplyDelete
  12. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Java Training in Bangalore

    ReplyDelete
    Replies
    1. Thanks for sharing your blog of information.Really a awesome post.keep on blogging.Selenium Training in Chennai |
      |Oracle Training in Chennai

      Delete
  13. Crush and smash film or still pictures as 3D pieces detonate to uncover the following picture from Pixel Film Studios. With the 3D camera and lights in Movement 5, clients can produce their smash results to the following level. Turn, rotate or container around the media as it breakes into many minor pieces. FCPX Motion Plugins

    ReplyDelete
  14. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!


    Java Training in Chennai


    Java Training in Bangalore


    Java Training in Bangalore

    ReplyDelete
  15. I have read your blog. Your information is really useful for beginner. informations provided here are unique and easy to understandThanks for this useful infromation. QTP Training in Chennai
    Java Training in Chennai
    Python Training in Chennai

    ReplyDelete
  16. Technology is in a growing way, if you want to shine your career just try to learn a latest technology skill which is having great scope in future.
    Best hadoop training institute in chennai|Big Data Hadoop Training in Chennai

    ReplyDelete
  17. Nice Info!

    It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Thank you for sharing Final Year Bca Project Centres Chennai | ME Projects Chennai.

    ReplyDelete
  18. It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Thank you for sharing Bio Medical Inplant Training in Chennai.

    ReplyDelete
  19. Thank you for posting this beneficial content material. You provided another one great article in bsc mini projects in chennai. I hope this information may change my business carrier.I can remember these things whenever taking the decision in realtime mini projects in chennai.

    ReplyDelete
  20. Really you shared the information is great and useful.I have learned new things.you also refer this ME Projects Chennai | Ns2 Projects in Chennai.

    Thank You.

    ReplyDelete
  21. Hi Admin,
    I went through your blog and it’s totally awesome. Keep on updating your site with such informative post.

    ECE Project Centers in Chennai | Embedded Mini Project Centers in Chennai

    ReplyDelete

  22. I have read your blog its very attractive and impressive.I like it your blog.

    Msc Project Centers in Chennai | Project Centers in Chennai.

    ReplyDelete
  23. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving. Most of ideas can be nice content. The people to give them a good shake to get your point and across the command
    Java training in Chennai
    informatica training in chennai
    oracle training in chennai
    selenium training in chennai
    hadoop training in chennai
    unix training in chennai
    Python training in Chennai

    ReplyDelete
  24. Nice Blog, Thanks for sharing this valuable one.This is very useful for me and gain more information,

    Angularjs Training in Chennai | Dot Net Training in Chennai

    ReplyDelete

  25. Thanks for sharing the information, Salesforce experts a lot of openings in multi-level companies, for more information n
    Salesforce Training
    Salesforce certification Training program Salesforce Online Training in BangaloreSalesforce Training online in India

    ReplyDelete
  26. It's a nice post. Thank you for sharing this useful information. Keep up the good work.

    IoT Training | IoT Courses

    ReplyDelete
  27. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.

    Mobile Apps Training
    Mobile Apps Training in Chennai

    ReplyDelete
  28. Very Nice Article to read. Blog articles helped me alot in many ways to find the good solution. Am very happy to comments here. Thanks for sharing this kind of wonderful article in this blog. Lovely ! MATRIX dealers

    ReplyDelete
  29. Thanks for sharing this unique information with us. Your post is really awesome. Your blog is really helpful for me..
    organic oil
    organic oil in jaipur
    organic cold pressed oils
    ayurvedic oil store in jaipur

    ReplyDelete
  30. Unquestionably believe that which you said. Your favorite justification seemed to be on the web the easiest thing to be aware of. I say to you, I definitely get irked while people think about worries that they just don't know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks seo service

    ReplyDelete
  31. You made some nice points there. I did a search on the subject and found most persons will approve with your site.online marketing

    ReplyDelete
  32. I needed to put you that little bit of word to give thanks as before regarding the awesome techniques you have discussed on this website. It's certainly tremendously open-handed with you in giving extensively all that numerous people could possibly have sold as an e book to earn some profit for themselves, and in particular now that you could possibly have tried it in the event you decided. These ideas likewise worked like a fantastic way to realize that someone else have a similar desire much like my own to figure out good deal more with reference to this matter. Certainly there are thousands of more pleasurable times ahead for those who read carefully your blog post.online marketing company

    ReplyDelete
  33. Iíve learn a few good stuff here. Certainly value bookmarking for revisiting. I wonder how so much effort you place to make the sort of excellent informative site. truck rental singapore

    ReplyDelete
  34. Howdy! I could have sworn I've been to this site before but after reading through some of the post I realized it's new to me. Anyways, I'm definitely delighted I found it and I'll be book-marking and checking back frequently! robotic systems integration

    ReplyDelete
  35. Hi my friend! I wish to say that this article is awesome, nice written and include almost all important infos. I would like to see more posts like this. sell your property

    ReplyDelete
  36. Great post. I was checking continuously this weblog and I am inspired! Very helpful info specifically the last phase :) I care for such information much. I used to be seeking this certain info for a long time. Thanks and best of luck. temporary fence hire prices

    ReplyDelete
  37. That is really interesting, You're a very professional blogger. I've joined your rss feed and look forward to looking for extra of your wonderful post. Additionally, I've shared your website in my social networks!preschool moorebank

    ReplyDelete
  38. Useful info
    Unic Sol is the best java training in Hyderabad with job placements. Along with java training full stack, mean stack, angular & testing tools training is provided by industry experts. We are the best java training in Hyderabad.

    ReplyDelete
  39. This comment has been removed by the author.

    ReplyDelete
  40. Thank you so much for this useful article. Visit OGEN Infosystem for Web Designing and SEO Services in Delhi, India.
    Website Designing Company

    ReplyDelete
  41. Is there anyone who can recommend the best service among the ones listed here for google seo class in singapore?

    ReplyDelete
  42. http://java.worldbestlearningcenter.com/2013/11/splash-screen.html?showComment=1571826500170#c124646149514112925

    ReplyDelete
  43. When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get three e-mails with the same comment. Is there any way you can remove people from that service? Bless you! aircon chemical overhaul

    ReplyDelete
  44. Hmm is anyone else experiencing problems with the images on this blog loading? I'm trying to find out if its a problem on my end or if it's the blog. Any suggestions would be greatly appreciated.small accounting firm in Singapore

    ReplyDelete
  45. I simply needed to thank you very much again. I am not sure what I would've achieved without the type of tricks documented by you directly on that area of interest. It seemed to be the difficult case in my circumstances, but being able to see a expert fashion you solved that took me to leap for fulfillment. I am grateful for the service and even believe you really know what an amazing job you were getting into teaching others with the aid of your web blog. I am sure you haven't got to know all of us.seiko prospex

    ReplyDelete
  46. Hi, i think that i saw you visited my blog so i came to “return the favor”.I'm attempting to find things to enhance my web site!I suppose its ok to use a few of your ideas!!origins skin care

    ReplyDelete
  47. hi!,I like your writing so much! share we communicate more about your post on AOL? I require a specialist on this area to solve my problem. Maybe that's you! Looking forward to see you.sport injury chiropractor singapore

    ReplyDelete
  48. I cling on to listening to the reports lecture about getting free online grant applications so I have been looking around for the finest site to get one. Could you advise me please, where could i find some?senja cashew swimming lessons

    ReplyDelete
  49. This post is so helpfull and interavtive.Keep updating with more informaion...
    Cyber Security Technologies
    Job In Security Company

    ReplyDelete
  50. This post is so helpfull and interavtive.I simply needed to thank you very much again. I am not sure what I would've achieved without the type of tricks documented by you directly on that area of interest.Best Datascience course in kochi 2024

    ReplyDelete