This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Classes" Watch "Classes" New topic
Author

Classes

Janner Aglith
Greenhorn

Joined: Jul 02, 2012
Posts: 1
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

Joined: Oct 13, 2005
Posts: 38441
    
  23
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Classes