Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classes

 
Janner Aglith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the paintComponent() in the Circle Class, I have the Circle accessing the super classes variables through methods, is there a better way to do this?




 
Campbell Ritchie
Sheriff
Pie
Posts: 49756
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct the way you are handling the return values. A Shape has location and colour. I am not convinced that a circle has radius and diameter; I would remove the diameter field and change the getDiameter method, if I need it at all:-The paintComponent method ought not to be part of the Shape class. It is part of the Component class, and should not be in other classes. It should also have protected access. How do you paint the shapes then? Start with this thread, which will probably answer that question.

And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic