java - PaintComponent not working for drawing shapes -


i studying graphics , tried use paintcomponent draw shapes, following code. trying hour still not working can't reason. resolution simple problem?

public class mypainting  extends jpanel {      public void paintcomponent (graphics g)      {         super.paintcomponent(g);         g.setcolor(color.red);         g.drawrect(100, 100, 10, 20);     }      public  static void main (string [] args)     {         mypainting p =  new mypainting();         jframe f= new jframe();         f.setsize(300,300);         f.setdefaultcloseoperation(jframe.exit_on_close);         f.add(p);                f.setvisible(true);     } } 

when run program there empty jframe, did try g.drawstring, imageicon every time nothing visible.

the method paintcomponent not defined in of super classes of jpanel. want paintcomponent

@override public void paintcomponent (graphics g)  

and add @override annotation allow compiler check correct method.


Comments