Drawing or Graphics APIs form an integral part of any language. They let you access the host operating system's GUI services. They are needed not only for implementing and rendering custom GUI controls and components for a standalone system; they also provide for non-GUI control based applications such as image manipulation, graph rendering functions and so on. Among current languages almost all provide drawing APIs. Java is no exception.
Java provides the Drawing APIs in the form of packages which are placed under the name Java 2D API. In this discussion I will focus on the basics of Java 2D API. I will discuss the whys and wherefores of the API, and enumerate the steps for using Java 2D API. In the second part of this article (which will appear tomorrow), I will focus on an example that demonstrates the various aspects of Java 2D. That's the outline for this discussion.
Java 2D API: What is it?
By definition Java 2D API is "a set of classes for advanced 2D graphics and imaging, encompassing line art, text, and images in a single comprehensive model providing extensive support for image compositing and alpha channel images, a set of classes to provide accurate color space definition and conversion, and a rich set of display-oriented imaging operators." The definition itself provides us with the types of functionalities provided by Java 2D. These functionalities can be divided into two major categories:
While the former deals exclusively with drawing (either on components or images), the latter is for dealing with images. Now let's look at the functionalities provided by each of them.