Skill-Building Exercises


Summary

There are several ways to load an Image from a URL, the easiest being to use the javax.imageio package introduced with Java 1.4. When time comes to deploy an application, it is wise to package its classes and other resources into a jar file and to load the resources from a dynamically constructed URL.

The Graphics and Graphics2D classes provide many sophisticated drawing tools. Their methods can be divided into three categories, drawing operations, property-related methods and a few miscellaneous methods. The AWT/ Swing framework handles the repainting of components. We can call one of a component’s repaint() methods to trigger the framework to repaint our component in response to application specific needs. Application specific painting code should be placed into the paint() method of an AWT component and into the paintComponent() method of a Swing component.

Swing’s separable model architecture creates a loose coupling between Components and the data they represent by defining data model interfaces with which the Components interact. This frees an application to manage its data as it wishes. As long as the data is wrapped in the appropriate interface, the Component will be automatically notified of changes in the data without any special effort on the part of the programmer.

JList, JComboBox, JTree and JTable are examples of faux-composite components that use renderers to create the illusion of having many children components without incurring the overhead of maintaining that many components. JList and JComboBox use ListCellRenderers, JTables use TableCellRenderers and JTrees use TreeCellRenderers. By implementing the correct renderer interface, a custom renderer can affect a faux-composite component’s appearance, tailoring it to the data it represents.

JTables, JTrees and JComboBoxes are able to edit their underlying data models and they provide methods for plugging in custom editors through a mechanism that is similar to plugging in custom renderers. To create a custom editor for a JTree or JTable it is easiest to extend AbstractCellEditor and implement either the TreeCellEditor or the TableCellEditor interface as required.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net