Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 17: Polymorphism > Polymorphism in a Drawing Application - Pg. 394

} } Color newColor = new Color(red, green, blue); component.setForeground(newColor); The brightenForegroundColor method takes a java.awt.Component object. Because the Component class is the parent class of all Swing controls, thanks to polymorphism you can pass any Swing component to brightenForegroundColor. This way, you only need one method for all components. Without polymorphism, you need a method for each type of component. You would have brightenJLabelForegroundColor, brightenJButtonForegroundColor, and so forth. Note The app17.MyFrame class allows you to test the brightenForegroundColor method.