It's very bad practice to sleep the user interface thread. (As this will cause the application to become unresponsive.) You ought to put all this code inside the Run() method of a Runnable instance:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// Your code here.
}
});