src/java.desktop/share/classes/java/awt/Canvas.java

Print this page




  76             if (peer != null) {
  77                 gc = peer.getAppropriateGraphicsConfiguration(gc);
  78             }
  79             super.setGraphicsConfiguration(gc);
  80         }
  81     }
  82 
  83     /**
  84      * Construct a name for this component.  Called by getName() when the
  85      * name is null.
  86      */
  87     String constructComponentName() {
  88         synchronized (Canvas.class) {
  89             return base + nameCounter++;
  90         }
  91     }
  92 
  93     /**
  94      * Creates the peer of the canvas.  This peer allows you to change the
  95      * user interface of the canvas without changing its functionality.
  96      * @see     java.awt.Toolkit#createCanvas(java.awt.Canvas)
  97      * @see     java.awt.Component#getToolkit()
  98      */
  99     public void addNotify() {
 100         synchronized (getTreeLock()) {
 101             if (peer == null)
 102                 peer = getToolkit().createCanvas(this);
 103             super.addNotify();
 104         }
 105     }
 106 
 107     /**
 108      * Paints this canvas.
 109      * <p>
 110      * Most applications that subclass <code>Canvas</code> should
 111      * override this method in order to perform some useful operation
 112      * (typically, custom painting of the canvas).
 113      * The default operation is simply to clear the canvas.
 114      * Applications that override this method need not call
 115      * super.paint(g).
 116      *
 117      * @param      g   the specified Graphics context
 118      * @see        #update(Graphics)
 119      * @see        Component#paint(Graphics)
 120      */
 121     public void paint(Graphics g) {
 122         g.clearRect(0, 0, width, height);




  76             if (peer != null) {
  77                 gc = peer.getAppropriateGraphicsConfiguration(gc);
  78             }
  79             super.setGraphicsConfiguration(gc);
  80         }
  81     }
  82 
  83     /**
  84      * Construct a name for this component.  Called by getName() when the
  85      * name is null.
  86      */
  87     String constructComponentName() {
  88         synchronized (Canvas.class) {
  89             return base + nameCounter++;
  90         }
  91     }
  92 
  93     /**
  94      * Creates the peer of the canvas.  This peer allows you to change the
  95      * user interface of the canvas without changing its functionality.

  96      * @see     java.awt.Component#getToolkit()
  97      */
  98     public void addNotify() {
  99         synchronized (getTreeLock()) {
 100             if (peer == null)
 101                 peer = getComponentFactory().createCanvas(this);
 102             super.addNotify();
 103         }
 104     }
 105 
 106     /**
 107      * Paints this canvas.
 108      * <p>
 109      * Most applications that subclass <code>Canvas</code> should
 110      * override this method in order to perform some useful operation
 111      * (typically, custom painting of the canvas).
 112      * The default operation is simply to clear the canvas.
 113      * Applications that override this method need not call
 114      * super.paint(g).
 115      *
 116      * @param      g   the specified Graphics context
 117      * @see        #update(Graphics)
 118      * @see        Component#paint(Graphics)
 119      */
 120     public void paint(Graphics g) {
 121         g.clearRect(0, 0, width, height);