Welcome to CodeRanch!
As Carey mentioned, the GUI layout code can become quite bulky, and may distract from more important things that are happening in the code, such as the initialization of fields. Usually this method is called
initializeComponents(), instead of
gui(). Remember that method names must be verbs that describe what the methods do.
I believe that by default, closing a
JFrame hides a window without actually disposing it. That means the event dispatch
thread will keep running and the application doesn't terminate.
Fields should be private and final, if possible. Don't make
f public. Also, give it a more descriptive name, such as
frame.
Never call
setVisible() or
pack() from a constructor, either directly or indirectly. They start up the event dispatch thread, and you must never start threads from constructors. Instead, put them in a separate method that is called by the same method that calls the constructor.