Q&A

Q1:Is there a way to use different colors in an interface?
A1: 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.
Q2:Do you need to do anything with the paint() method or repaint() to indicate that a text field has been changed?
A2: 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.
Q3:Why do you often import a class ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.