Is there a way to use different colors in an interface?


You can use Color objects to change the appearance of each component in several ways. The setBackground() method designates the background elements, and setForeground() sets foreground elements. You must use these methods with the components themselves. The setBackground() method of the applet will not change the color of containers and components within the applet.


Do you need to do anything with the paint() method or repaint() to indicate that a text field has been changed?


After the setText() method of a text component is used to change its value, nothing else needs to be done. Swing handles the updating necessary to show the new value.


Why do you often import a class and also one of its sub-classes, as in Listing 15.1 when you import java.awt.* and java.awt.event.*. Couldn't the first of these statements include the second?


Though the names of the java.awt and java.awt.event packages look like they are related, there's no such thing as inheritance for packages in Java. One package cannot be a subpackage of another. When you use an asterisk in an import statement, you are making all of the classes in a package available in a program. The asterisk only works on classes, not packages. The most a single import statement can load is the classes of a single package.


Why is Massachusetts referred to as a commonwealth instead of a state?


A commonwealth is a government formed by common consent of its people, and the term was preferred over state by the founders of Kentucky, Massachusetts, Pennsylvania, and Virginia. When John Adams wrote the second draft of the Massachusetts state constitution in 1780, it was retitled from the "State of Massachusetts-Bay" to the "Commonwealth of Massachusetts." Other than the name, there's no legal difference between commonwealths and states. The 17th century meaning of the term commonwealth is comparable to today's definition for a republic. The U.S. government also uses commonwealth to describe territories under Congressional control that have limited self-government over internal affairs, such as the Northern Marian Islands and Puerto Rico.