• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using the 2D API

From its earliest days, Java has included a nice graphics class called java.awt. Graphics. To graphics professionals, however, Graphics left some features to be desired. More mature GUI platforms, such as Windows 95 and the Macintosh, support features that are not present in Graphics.

Now, in JDK 1.2, all that has changed. Sun has provided a much richer, two-dimensional graphics class called java.awt.Graphics2D. This section describes the major improvements available in Graphics2D. Listing 39.18 shows a demonstration program, PathsFill.java, that shows how to display shapes by using Graphics2D. The PathsFill class is a type of Canvas, so Graphics2D is able to draw on it by casting the Graphics parameter to paint() as a Graphics2D. The class also contains a main() method, enabling us to run it from the command line. Compile PathsFill.java by typing


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint