Shakran, cj, and abaya are right. Here's my slightly different take:
1. Success is the best revenge. Visualize seeing her down the road when you're successful, and the other guy isn't.
2. (This is what I do a lot) Visualize how someone you admire would handle this situation. Gandhi, 007, I don't care. (Maybe Adam Sandler as Happy Gilmore wouldn't be a good choice. )
3. If you're not damn sure he's not going to punch you back, think how bad you'd feel about losing your ex AND getting your ass kicked.
4. I don't think he's the root of the problem. I think your ex is. Had the relationship been strong, he wouldn't have been a factor. Not that I'm saying it's the right thing to do, but punching him would have been a lot more appropriate if you were still with your ex and he kept hitting on her.
Also remember, as someone said earlier, that if you're over 17, that punch can follow you for the rest of your life.
Find another girl and be a lover, not a fighter.