What you may be missing here is that you're creating components for use by the AWT. When you call setVisible on the frame, the AWT event
thread takes over and manages the application.
Have you wondered what happens to the application when the main() method is finished? Perhaps you haven't noticed, but that method finishes and the original thread that started it is done. The application then run via the AWT event thread.
I mention this because of your comment that one of your 'b' variables was still set. In actuality, after main() ends, all the local variables are out of scope (both 'b' and 'f').
By the way, for a simple
test application, it's okay to create graphical components in the main application thread. However,
you should get in the habit of creating all graphical components in the AWT event thread, using EventQueue.invokeLater(...); Here is an example: