Actually paint is method which call whenever classis called. So, when you call it through f.show();It is definitely paint that will be displayed.for overcome it, you have to do it in some othermanual function. /paint is the program function