The application flashing (hide and show) every time it gains/loses focus is really annoying and makes this scheme not realistic for any real application. I don't understand why we have to hide and show the frame. Why can't we just update the background, and the next time paintComponent is called it will use the new background image? Why do we need to actually hide and show the frame?
There is a minor bug. After launching the app it will flash after 1 second even if you haven't done anything I assume because after the window is painted we get a windowGainedFocus event which causes it to update the background.