Headphones work in two ways: as a signal to others that you don't want to be disturbed and the audio signal should drown out environmental noise and prevent you from becoming distracted.
And practicing meditation can't hurt, it'll help with focusing.
I have to second the headphones idea. And if you don't think you like techno or trance music, you might change your mind after you code while listening to it (which is about the only time I listen to it).
Stuff with a white-noisy background and a steady, brisk rhythm tends to block out the din of the workplace and helps me stay focused for longer periods of time. Was the only way I could cope with the loud, obnoxious sales staff sitting nearby. Oh, and avoid music with lyrics.
Similarly, jazz and classical work beautifully as working music. I code most often to Gould, and my favorite music for mental jams is to put my Thelonious Monk collection on shuffle.
And practicing meditation can't hurt, it'll help with focusing.