You have a massive issue. Wait, that's not big enough:
A Massive Issue
Better.
You are busy waiting in a do
loop and spinning up a new Timer
each time:
do {
Timer timer = new Timer();
//some other stuff
} while (newUser.isVisible());
This is causing thousands (millions?) of Timer
instances to be created, each with its own Thread
.
- never busy wait
- don't create thousands of
Timer
instances
Further, you are using the java.util.Timer
not the javax.swing.Timer
which means that the eventual action is not executed on the EDT.
This is a violation if the Swing threading policy. Swing objects, except in rare case, are not thread safe and should only be accessed from the EDT.
In short; there is very little that isn't wrong with this code.