
We all know the importance of user interface in any commercial as well as non commercial software. Today while working on one of my project I felt that the loading time of my application is quite longer than usual.
The reasons behind longer loading time are the loading of configuration file and downloading of resources from web. Here splash screen is the requirement for this situation.
Although there are many ways to implement splash screen in java but I prefer the built in API for splash screen. Let's see how to use this native Splash screen API for your application.
Java SE 6 provides a solution that allows the application to display the splash screen much earlier, even before the virtual machine starts. A Java application launcher is able to decode an image and display it in a simple non-decorated window.
Below is the sample Java Swing application that do some time consuming task before initializing UI.
Copy and save below code in file MySplashScreenDemo.java
package com.decryptoniter.splash;
import java.awt.FlowLayout;
import javax.swing.*;
public class MySplashScreenDemo {
MySplashScreenDemo() {
// some time consuming task before UI initialization
someTask();
// UI will initialize now
initUI();
}
void someTask() {
System.out.println("Some time consuming task is executed");
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
void initUI() {
JFrame frame = new JFrame("Splash Screen Demo");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JLabel label = new JLabel("www.isumitjha.com");
panel.add(label);
frame.add(panel);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
System.out.println("UI initialized");
}
public static void main(String s[]) {
MySplashScreenDemo ss = new MySplashScreenDemo();
}
}
Now compile MySplashScreenDemo.java:
javac -d . MySplashScreenDemo.java
Run this application: java com.decryptoniter.splash.MySplashScreenDemo
You will notice that it takes 15 seconds to load the UI after running the application. Now to display splash screen while UI is not loaded we can use java command line argument.
Display a Splash Screen using the Command-Line Argument
To display a splash screen from the command line use the -splash: command-line argument. This argument is a Java application launcher option that displays a splash screen:java -splash:<file name> <class name>
For our application use. java -splash:loading.gif com.decryptoniter.splash.MySplashScreenDemo
Now you can see the splash screen as soon as application is run while UI is not loaded.
Note: The splash screen can display any gif, png, or jpeg image, with transparency, translucency, and animation.
very good introduction night geekowl
ReplyDeleteplus the information
I am glad that you like the article and intro too :p
DeleteReally very interesting and useful article of the developers like me.
ReplyDeleteJava Training in Chennai
Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.Thanks for sharing. Anybody want to learn
ReplyDeleteCore Java Online Training
Your information about Java is useful for me to know more technical information. Really very informative post you shared here. Keep sharing this type of informative blog. If anyone wants to become a Java professional learn Java Training in Bangalore. Nowadays Java has tons of job opportunities for all professionals...Big Data Hadoop Training in Bangalore | Data Science Training in Bangalore
ReplyDeleteIt'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.
ReplyDeleteJava Training in BTM Layout
Java Training in Marathahalli
I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
ReplyDeleteJava Training in Bangalore|
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeletehttp://www.traininginmarathahalli.in/
I feel really happy to have seen your webpage and look forward to so
ReplyDeletemany more entertaining times reading here. Thanks once more for all
the details.
Selenium Training in Chennai
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyDeleteData Science Training in Bangalore
Datascience Training in Chennai
I really enjoy your post.I will be waiting for your another blog & i want more Java Training in Chennai
ReplyDeleteOracle Training in Chennai
• Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Power Bi Online Training Hyderabad
ReplyDeleteI believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteSelenium Training in Bangalore
Selenium Training in BTM
Selenium Training in Rajaji Nagar
Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition. Selenium Training In Bangalore | Best Selenium Training in Bangalore
ReplyDelete