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
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