I am trying to make a login picture for my application using Timer
. The idea is, when the user opens the application, he will see a picture for 5 seconds, then the
The idea is, when the user opens the application, he will see a picture for 5 seconds, then the application will start.
You should use a Splash Screen. The advantage of the splash screen is the image is displayed immediately as the whole Swing app doesn't need to be loaded.
Check out the section from the Swing tutorial on How to Create a Splash Screen for more information and a working example.
Start by creating the Timer
once in the constructor. The Timer
should, also, only make the CURRENT instance of login
close
public login() {
//...
time = new Timer(5000,new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
timer.setRepeats(false);
}
In the shoutoff
method, you start timer...
public void shoutoff(){
if (!time.isRunning()) {
timer.start();
}
}
Take a closer look at How to use Swing Timers for more details.
You might like to have a read through Code Conventions for the Java TM Programming Language, it will make it easier for people to read your code and for you to read others