Kishan -
The default size of the frame is very small so when you do a setVisible()
Java tries to display a tiny frame (just remove your setSize() and see). When you call setSize() the Frame changes size, but does not redraw it's contents unless specifically told to. (via setVisible() again) So, it's a good idea to call setSize() then setVisible().
BTW - try this code... it's pretty fun...
-Nate