home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / Canvas.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.3 KB  |  116 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Canvas.java    1.21 98/07/10
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.peer.CanvasPeer;
  17.  
  18. /**
  19.  * A <code>Canvas</code> component represents a blank rectangular 
  20.  * area of the screen onto which the application can draw or from 
  21.  * which the application can trap input events from the user. 
  22.  * <p>
  23.  * An application must subclass the <code>Canvas</code> class in 
  24.  * order to get useful functionality such as creating a custom 
  25.  * component. The <code>paint</code> method must be overridden 
  26.  * in order to perform custom graphics on the canvas.
  27.  *
  28.  * @version     1.21 07/10/98
  29.  * @author     Sami Shaio
  30.  * @since       JDK1.0
  31.  */
  32. public class Canvas extends Component {
  33.  
  34.     private static final String base = "canvas";
  35.     private static int nameCounter = 0;
  36.     
  37.     /*
  38.     * A reference to a GraphicsConfiguration object
  39.     * used to describe the characteristics of a graphics
  40.     * destination.
  41.     * 
  42.     * @serial
  43.     * @see java.awt.GraphicsConfiguration
  44.     */
  45.     private GraphicsConfiguration graphicsConfig = null;
  46.  
  47.     /*
  48.      * JDK 1.1 serialVersionUID 
  49.      */
  50.      private static final long serialVersionUID = -2284879212465893870L;
  51.  
  52.     /** 
  53.      * Constructs a new Canvas.
  54.      */
  55.     public Canvas() {
  56.     }
  57.  
  58.     /** 
  59.      * Constructs a new Canvas given a GraphicsConfiguration object.
  60.      * 
  61.      * @param config a reference to a GraphicsConfiguration object.
  62.      *
  63.      * @see GraphicsConfiguration
  64.      */
  65.     public Canvas(GraphicsConfiguration config) {
  66.         this();
  67.         graphicsConfig = config;
  68.     }
  69.  
  70.     /**
  71.      * Construct a name for this component.  Called by getName() when the
  72.      * name is null.
  73.      */
  74.     String constructComponentName() {
  75.         synchronized (getClass()) {
  76.         return base + nameCounter++;
  77.     }
  78.     }
  79.  
  80.     /**
  81.      * Creates the peer of the canvas.  This peer allows you to change the 
  82.      * user interface of the canvas without changing its functionality.
  83.      * @see     java.awt.Toolkit#createCanvas(java.awt.Canvas)
  84.      * @see     java.awt.Component#getToolkit()
  85.      */
  86.     public void addNotify() {
  87.         synchronized (getTreeLock()) {
  88.         if (peer == null)
  89.             peer = getToolkit().createCanvas(this);
  90.         super.addNotify();
  91.     }
  92.     }
  93.  
  94.     /**
  95.      * This method is called to repaint this canvas. Most applications 
  96.      * that subclass <code>Canvas</code> should override this method in 
  97.      * order to perform some useful operation. 
  98.      * <p>
  99.      * The <code>paint</code> method provided by <code>Canvas</code> 
  100.      * redraws this canvas's rectangle in the background color. 
  101.      * <p>
  102.      * The graphics context's origin (0, 0) is the top-left corner 
  103.      * of this canvas. Its clipping region is the area of the context. 
  104.      * @param      g   the graphics context.
  105.      * @see        java.awt.Graphics
  106.      */
  107.     public void paint(Graphics g) {
  108.     g.setColor(getBackground());
  109.     g.fillRect(0, 0, width, height);
  110.     }
  111.  
  112.     boolean postsOldMouseEvents() {
  113.         return true;
  114.     }
  115. }
  116.