Hi Krishna and welcome to the Ranch!
If that's Swing or AWT, you shouldn't be using
getGraphics() of a component, nor should you ever call a painting method from client code -- call
repaint() instead. That said, your code snippet doesn't make much sense in isolation. To get better help sooner, post a
SSCCE that clearly demonstrates your problem.
Again, if that's Swing, why aren't you using
JLabel and its
setText(...) method instead of messing around with custom painting? And what's a tab-out event?