Page 580 - Introduction to Programming with Java: A Problem Solving Approach
P. 580
546 Chapter 13 Inheritance and Polymorphism
Apago PDF Enhancer
Figure 13.23 Three-dimensional portrayal of a solid cylinder
get painted properly, if you ever implement an overriding paintComponent method, you should always call the paintComponent method the superclass defines or inherits as the first line in your overriding paintComponent method. Here’s the relevant code from Figure 13.24b:
super.paintComponent(g);
By definition, when a method overrides another method, the two methods must have the exact same signature (same name and same sequence of parameter types). Since the PaintComponent method in JComponent declares a Graphics object parameter, the PaintComponent method in Cylinder also declares a Graphics object parameter, named g. Even though g is declared as a Graphics object, the JVM actually passes a Graphics2D argument to the g parameter. That’s a good thing because the Cylinder class relies on the g parameter to perform sophisticated graphics operations found only in the Graphics2D class. The Graphics2D class is a subclass of Graphics. As you may recall from ear-