> graphics in java ~ Online tutorial

graphics in java

Graphics Contexts and Graphics Objects
  • A Java graphics context enables drawing on the screen.
  • A Graphics object manages agraphics context by controlling how information is drawn.
  • Graphics objects contain methods for drawing, font manipulation, color manipulation and the like.
  • Every applet we
    have seen in the text that performs drawing on the screen has used the Graphics object
    g (the argument to the applet’s paint method)  to manage the applet’s graphics context.
  • we demonstrate drawing in applications. However, every technique shown
    here can be used in applets.
  • The Graphics class is an abstract class (i.e., Graphics objects cannot be
    instantiated). This contributes to Java’s portability. Because drawing is performed differently
  • on each platform that supports Java, there cannot be one class that implements
    drawing capabilities on all systems.
  • For example, the graphics capabilities that enable a PC running Microsoft Windows to draw a rectangle are different from the graphics capabilities that enable a UNIX workstation to draw a rectangle—and those are both different from the graphics capabilities that enable a Macintosh to draw a rectangle.
  • When Java is implemented on each platform, a derived class of Graphics is created that actually implements all the drawing capabilities.
  • This implementation is hidden from us by the Graphics class, which supplies the interface that enables us to write programs that use graphics in a platform-independent manner.
  • Class Component is the superclass for many of the classes in the java.awt
    package .

     public void paint( Graphics g )
  • The paint object paint receives a reference to an object of the system’s derived
    Graphics class.
  • The preceding method header should look familiar to you—it is the same one we have been using in our applet classes. Actually, the Component class is an indirect base class of class JApplet—the superclass of every applet in this book.
  • Many capabilities
    of class JApplet are inherited from class Component.
  • The paint method defined in class Component does nothing by default—it must be overridden by the programmer.

  • Buy It Now 

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
Powered By: BloggerYard.Com