graphics method in a class extending jFrame

for example in my program i want to draw a colorful line and before using getgraphics().drawline(..) i want to set the color to something by using setcolor() method.

is it possible to use the methods getGraphics().setColor(Color...) in a class extending JFrame?i have a problem here. Whenever i used it the color didn't change.

[341 byte] By [dogukana] at [2007-11-27 11:59:01]
# 1

You don't do custom painting in a JFrame. You extend JComponent or JPanel and override the paintComponent(...) method.

Read the Swing tutorial on "Custom Painting" for more information and examples:

http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

camickra at 2007-7-29 19:23:14 > top of Java-index,Desktop,Core GUI APIs...
# 2

in my JFrame i have a Jpanel and i let the user only paint in this area.

or i can need another solution

i can write another class that is extending jpanel and overriding the void paint method but in my first class can i change the jpanel with the other one?i can remove the existing and add the new one but my frame includes many components so i automaticly set them by using netbeans. what can i do?or which one can i achieve?

dogukana at 2007-7-29 19:23:14 > top of Java-index,Desktop,Core GUI APIs...