001: /*
002: * @(#)Canvas.java 1.35 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package java.awt;
028:
029: import java.awt.event.PaintEvent;
030: import java.util.Timer;
031: import java.util.TimerTask;
032:
033: /**
034: * A <code>Canvas</code> component represents a blank rectangular
035: * area of the screen onto which the application can draw or from
036: * which the application can trap input events from the user.
037: * <p>
038: * An application must subclass the <code>Canvas</code> class in
039: * order to get useful functionality such as creating a custom
040: * component. The <code>paint</code> method must be overridden
041: * in order to perform custom graphics on the canvas.
042: *
043: * @version 1.31, 08/19/02
044: * @author Nicholas Allen
045: * @since JDK1.0
046: */
047: public class Canvas extends Component {
048: private static final String base = "canvas";
049: private static int nameCounter = 0;
050: /*
051: * JDK 1.1 serialVersionUID
052: */
053: private static final long serialVersionUID = -2284879212465893870L;
054:
055: /**
056: * Constructs a new Canvas.
057: */
058: public Canvas() {
059: }
060:
061: /**
062: * Construct a name for this component. Called by getName() when the
063: * name is null.
064: */
065: String constructComponentName() {
066: return base + nameCounter++;
067: }
068:
069: boolean isLightweightWhenDisplayable() {
070: return false;
071: }
072:
073: public void update(Graphics g) {
074: g.clearRect(0, 0, width, height);
075: paint(g);
076: }
077:
078: /**
079: * This method is called to repaint this canvas. Most applications
080: * that subclass <code>Canvas</code> should override this method in
081: * order to perform some useful operation.
082: * <p>
083: * The <code>paint</code> method provided by <code>Canvas</code>
084: * redraws this canvas's rectangle in the background color.
085: * <p>
086: * The graphics context's origin (0, 0) is the top-left corner
087: * of this canvas. Its clipping region is the area of the context.
088: * @param g the graphics context.
089: * @see java.awt.Graphics
090: * @since JDK1.0
091: */
092: public void paint(Graphics g) {
093: g.setColor(getBackground());
094: g.fillRect(0, 0, width, height);
095: }
096:
097: boolean postsOldMouseEvents() {
098: return true;
099: }
100: }
|