java - Why does this print out twice? -


i've noticed when use paintcomponent in java if use system.out.println(); things print out 2, 3, , 4 times. know when use extends jpanel automatically called, why more once.

here code try yourself.

import javax.swing.*; import java.awt.*;  public class stack extends jpanel{ public stack(){     jframe frame = new jframe();     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setvisible(true);     frame.add(this);     frame.setlocationrelativeto(null);     frame.setsize(200, 200);     } public static void main(string args[]){     stack s = new stack();     } public void paintcomponent(graphics g){     super.paintcomponents(g);     g.drawstring("thank you!", 100, 100);     system.out.println("why?"); } } 

system.out.println gets called once - method called repeatedly. everytime paintcomponent called prints why?.

this method being called multiple times, ie, frame resizes or such , in turn makes appear sysout being executed more once.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -