home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / Canvas.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  2.9 KB  |  95 lines

  1. /*
  2.  * @(#)Canvas.java    1.17 98/03/18
  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.17 03/18/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.     private GraphicsConfiguration graphicsConfig = null;
  37.  
  38.     /*
  39.      * JDK 1.1 serialVersionUID 
  40.      */
  41.      private static final long serialVersionUID = -2284879212465893870L;
  42.  
  43.     /** 
  44.      * Constructs a new Canvas.
  45.      */
  46.     public Canvas() {
  47.         this.name = base + nameCounter++;
  48.     }
  49.  
  50.     /** 
  51.      * Constructs a new Canvas given a GraphicsConfiguration object.
  52.      * 
  53.      * @param config a reference to a GraphicsConfiguration object.
  54.      *
  55.      * @see GraphicsConfiguration
  56.      */
  57.     public Canvas(GraphicsConfiguration config) {
  58.         this();
  59.         graphicsConfig = config;
  60.     }
  61.  
  62.     /**
  63.      * Creates the peer of the canvas.  This peer allows you to change the 
  64.      * user interface of the canvas without changing its functionality.
  65.      * @see     java.awt.Toolkit#createCanvas(java.awt.Canvas)
  66.      * @see     java.awt.Component#getToolkit()
  67.      */
  68.     public void addNotify() {
  69.     peer = getToolkit().createCanvas(this);
  70.     super.addNotify();
  71.     }
  72.  
  73.     /**
  74.      * This method is called to repaint this canvas. Most applications 
  75.      * that subclass <code>Canvas</code> should override this method in 
  76.      * order to perform some useful operation. 
  77.      * <p>
  78.      * The <code>paint</code> method provided by <code>Canvas</code> 
  79.      * redraws this canvas's rectangle in the background color. 
  80.      * <p>
  81.      * The graphics context's origin (0, 0) is the top-left corner 
  82.      * of this canvas. Its clipping region is the area of the context. 
  83.      * @param      g   the graphics context.
  84.      * @see        java.awt.Graphics
  85.      */
  86.     public void paint(Graphics g) {
  87.     g.setColor(getBackground());
  88.     g.fillRect(0, 0, width, height);
  89.     }
  90.  
  91.     boolean postsOldMouseEvents() {
  92.         return true;
  93.     }
  94. }
  95.