Help me with graphics

Hi,
I am trying to learn Graphics2D. I read all those tutorials about Graphics2D from Java website but I am not being able to understand it. I mean, I can draw a line and all but I am trying to create this simple program where there's a button and when user clicks that button a line is drawn somewhere in the JFrame but I am not being able to. Can anyone help me in this or give me a simple code so I can learn from it?
Thank you!!!

You need to use the Graphics object provided by the JComponent in its paintComponent method. I'm sorry if this sounds Greek to you, but my other recommendation will help translate this: if you are really serious about doing graphics programming in Java, buy the book "Filthy Rich Clients" by Guy and Haase.. It contains a gold-mine of first-class information on how to do Graphics coding. You won't regret it.

I figured it out myself. I need to initialize it to getGraphics(). Thanks anyway.

No, this is wrong.

Your image will not persist if the GUI ever has to be repainted (for example minimized then restored). Please read the tutorials and use the Graphics object returned by paintComponent as I suggested and as the Graphics tutorial will tell you as well.

You're creating a MyDrawingP object but where is it being placed so that it is visible on the JFrame or JDialog or JApplet? Just creating a JPanel even if you call setVisible(true) on it will not make it visible. You first need to eithr place it into a root container or in another container that eventually sits in a root container. To learn more about this, read the Sun Swing tutorials on creating and using Frames and Panels.

I can reproduce and modify the examples given in the Sun Swing tutorials, which deal with drawing in the main panel, but I cannot find how to anchor a drawing into an internal container within the main panel.
Could anyone point me to where I could find clues on how to do that?