• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

paintComponent(Graphics g);

 
Josh King
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add the component to a JFrame
show the frame
java will handle the painting
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

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.

Moving to a more suitable forum...
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Josh King
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic