Using Gcs

As we have said, using gcs and using graphics attributes of drawables may be freely intermixed. For example, you may have an application that usually wants a certain set of graphics attributes for a window, but occasionally wants a very different set. You could handle this by setting up the graphics attributes of the window, and changing them when necessary. Or you could create two gcs, one with each of the needed sets of graphics attributes, and specify the correct gc in each drawing command. Or you could set the graphics attributes of the window to the most often needed configuration, and create a separate gc with the alternate set of attributes, and only specify a gc argument in drawing commands when you need the alternate set. Each of these approaches has its advantages and disadvantages; which you choose is up to you.

It is also possible to set the gc a drawable will use when no gc is specified in a drawing command. If you need to create many windows or pixmaps with the same graphics attributes, this is an efficient way to do it. You create the gc with the attributes needed by all these windows, and then when you create the windows, you specify this as their gc.