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

Print this page


   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 151     public Button(String label) throws HeadlessException {
 152         GraphicsEnvironment.checkHeadless();
 153         this.label = label;
 154     }
 155 
 156     /**
 157      * Construct a name for this component.  Called by getName() when the
 158      * name is null.
 159      */
 160     String constructComponentName() {
 161         synchronized (Button.class) {
 162             return base + nameCounter++;
 163         }
 164     }
 165 
 166     /**
 167      * Creates the peer of the button.  The button's peer allows the
 168      * application to change the look of the button without changing
 169      * its functionality.
 170      *
 171      * @see     java.awt.Toolkit#createButton(java.awt.Button)
 172      * @see     java.awt.Component#getToolkit()
 173      */
 174     public void addNotify() {
 175         synchronized(getTreeLock()) {
 176             if (peer == null)
 177                 peer = getToolkit().createButton(this);
 178             super.addNotify();
 179         }
 180     }
 181 
 182     /**
 183      * Gets the label of this button.
 184      *
 185      * @return    the button's label, or <code>null</code>
 186      *                if the button has no label.
 187      * @see       java.awt.Button#setLabel
 188      */
 189     public String getLabel() {
 190         return label;
 191     }
 192 
 193     /**
 194      * Sets the button's label to be the specified string.
 195      *
 196      * @param     label   the new label, or <code>null</code>
 197      *                if the button has no label.


   1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 151     public Button(String label) throws HeadlessException {
 152         GraphicsEnvironment.checkHeadless();
 153         this.label = label;
 154     }
 155 
 156     /**
 157      * Construct a name for this component.  Called by getName() when the
 158      * name is null.
 159      */
 160     String constructComponentName() {
 161         synchronized (Button.class) {
 162             return base + nameCounter++;
 163         }
 164     }
 165 
 166     /**
 167      * Creates the peer of the button.  The button's peer allows the
 168      * application to change the look of the button without changing
 169      * its functionality.
 170      *

 171      * @see     java.awt.Component#getToolkit()
 172      */
 173     public void addNotify() {
 174         synchronized(getTreeLock()) {
 175             if (peer == null)
 176                 peer = getComponentFactory().createButton(this);
 177             super.addNotify();
 178         }
 179     }
 180 
 181     /**
 182      * Gets the label of this button.
 183      *
 184      * @return    the button's label, or <code>null</code>
 185      *                if the button has no label.
 186      * @see       java.awt.Button#setLabel
 187      */
 188     public String getLabel() {
 189         return label;
 190     }
 191 
 192     /**
 193      * Sets the button's label to be the specified string.
 194      *
 195      * @param     label   the new label, or <code>null</code>
 196      *                if the button has no label.