Search code examples
c#javaswingonpaint

OnPaint() for Java?


All right real quick question guys. I know that C# Forms have the OnPaint() method that keeps on being called when its time to render. I know Java has a similar one but I am lost on how to implement it. Any pointers or example(prefferred) will be very much appreciated. Thanks a lot.


Solution

  • If using Swing, refrain from painting in a top level container (e.g. JApplet or JFrame) and use a JComponent or JPanel.

    For custom painting in the latter two classes, use paintComponent(Graphics).