Michail Petrov wrote:Why i nead to extends JPanel for using paintComponent(Graphics g)
Do you mean as opposed to overriding the paint method? In Swing the paintComponent method's role is to paint the component whereas paint's role is to paint the component, its borders and its children. If your painting doesn't involve changing the painting of the borders and the child components (and most do not), then you're far better off and much less likely to muck things up by overriding JPanel's paintComponent [corrected] method rather than its paint method.
If you mean why should I extend JPanel and paint in there rather than JFrame, well, I don't know all the reasons for this, but one is that if you do this, you loose some of the benefits of painting in Swing such as Swing's automatic double buffering (without which animations will look choppy). I'm sure that there are several other good reasons too as painting a JFrame can get quite tricky, what with all its components.