home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Javadraw / DATA.Z / Canvas.java < prev    next >
Text File  |  1997-08-30  |  3KB  |  92 lines

  1. /*
  2.  * @(#)Canvas.java    1.14 97/06/12 Sami Shaio
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22. package java.awt;
  23.  
  24. import java.awt.peer.CanvasPeer;
  25.  
  26. /**
  27.  * A <code>Canvas</code> component represents a blank rectangular 
  28.  * area of the screen onto which the application can draw or from 
  29.  * which the application can trap input events from the user. 
  30.  * <p>
  31.  * An application must subclass the <code>Canvas</code> class in 
  32.  * order to get useful functionality such as creating a custom 
  33.  * component. The <code>paint</code> method must be overridden 
  34.  * in order to perform custom graphics on the canvas.
  35.  *
  36.  * @version     1.14 06/12/97
  37.  * @author     Sami Shaio
  38.  * @since       JDK1.0
  39.  */
  40. public class Canvas extends Component {
  41.  
  42.     private static final String base = "canvas";
  43.     private static int nameCounter = 0;
  44.  
  45.     /*
  46.      * JDK 1.1 serialVersionUID 
  47.      */
  48.      private static final long serialVersionUID = -2284879212465893870L;
  49.  
  50.     /** 
  51.      * Constructs a new Canvas.
  52.      */
  53.     public Canvas() {
  54.         this.name = base + nameCounter++;
  55.     }
  56.  
  57.     /**
  58.      * Creates the peer of the canvas.  This peer allows you to change the 
  59.      * user interface of the canvas without changing its functionality.
  60.      * @see     java.awt.Toolkit#createCanvas(java.awt.Canvas)
  61.      * @see     java.awt.Component#getToolkit()
  62.      * @since   JDK1.0
  63.      */
  64.     public void addNotify() {
  65.     peer = getToolkit().createCanvas(this);
  66.     super.addNotify();
  67.     }
  68.  
  69.     /**
  70.      * This method is called to repaint this canvas. Most applications 
  71.      * that subclass <code>Canvas</code> should override this method in 
  72.      * order to perform some useful operation. 
  73.      * <p>
  74.      * The <code>paint</code> method provided by <code>Canvas</code> 
  75.      * redraws this canvas's rectangle in the background color. 
  76.      * <p>
  77.      * The graphics context's origin (0, 0) is the top-left corner 
  78.      * of this canvas. Its clipping region is the area of the context. 
  79.      * @param      g   the graphics context.
  80.      * @see        java.awt.Graphics
  81.      * @since      JDK1.0
  82.      */
  83.     public void paint(Graphics g) {
  84.     g.setColor(getBackground());
  85.     g.fillRect(0, 0, width, height);
  86.     }
  87.  
  88.     boolean postsOldMouseEvents() {
  89.         return true;
  90.     }
  91. }
  92.