Ive been confused a litttle about the paintcomponent that i cant run it. i have the code below
i think that you can call on the methodyou self but i wanted to see the rectangle in a realtime GUI but obvisly i have no main method.
i just wanted to know how would i be able to run this small graphic???
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
add the component to a JFrame show the frame
java will handle the painting
In future, while posting code, please UseCodeTags. I have added them for you this time. As you can see the code tags, make the code much more easier to read and understand.
And make the paintComponent() method protected, rather than public. It ought not to be called from any of your code; you leave the JVM to call it. And lots of people seem to ask the same question.
Additionally, as far as possible don't name your own classes the same as a JDK class, and especially not a JDK class that you use in your code.
Your class extending JPanel should not be named Graphics.
luck, db
There are no new questions, but there may be new answers.
Josh King
Greenhorn
Joined: Jul 04, 2012
Posts: 2
posted
0
Thanks guys for the tips didnt even know i had to have the mthod protected but i named it Graphics just for example. i really didnt think i get a response so thnanks.