java.awt

Class Button

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public class Button
    extends Component
    implements Accessible
    This class creates a labeled button. The application can cause some action to happen when the button is pushed. This image depicts three views of a "Quit" button as it appears under the Solaris operating system:

    The following context describes the graphic

    The first view shows the button as it appears normally. The second view shows the button when it has input focus. Its outline is darkened to let the user know that it is an active object. The third view shows the button when the user clicks the mouse over the button, and thus requests that an action be performed.

    The gesture of clicking on a button with the mouse is associated with one instance of ActionEvent, which is sent out when the mouse is both pressed and released over the button. If an application is interested in knowing when the button has been pressed but not released, as a separate gesture, it can specialize processMouseEvent, or it can register itself as a listener for mouse events by calling addMouseListener. Both of these methods are defined by Component, the abstract superclass of all components.

    When a button is pressed and released, AWT sends an instance of ActionEvent to the button, by calling processEvent on the button. The button's processEvent method receives all events for the button; it passes an action event along by calling its own processActionEvent method. The latter method passes the action event on to any action listeners that have registered an interest in action events generated by this button.

    If an application wants to perform some action based on a button being pressed and released, it should implement ActionListener and register the new listener to receive events from this button, by calling the button's addActionListener method. The application can make use of the button's action command as a messaging protocol.

    Since:
    JDK1.0
    See Also:
    ActionEvent, ActionListener, Component.processMouseEvent(java.awt.event.MouseEvent), Component.addMouseListener(java.awt.event.MouseListener), Serialized Form
    • Method Detail

      • getLabel

        public String getLabel()
        Gets the label of this button.
        Returns:
        the button's label, or null if the button has no label.
        See Also:
        setLabel(java.lang.String)
      • setLabel

        public void setLabel(String label)
        Sets the button's label to be the specified string.
        Parameters:
        label - the new label, or null if the button has no label.
        See Also:
        getLabel()
      • setActionCommand

        public void setActionCommand(String command)
        Sets the command name for the action event fired by this button. By default this action command is set to match the label of the button.
        Parameters:
        command - a string used to set the button's action command. If the string is null then the action command is set to match the label of the button.
        Since:
        JDK1.1
        See Also:
        ActionEvent
      • getActionCommand

        public String getActionCommand()
        Returns the command name of the action event fired by this button. If the command name is null (default) then this method returns the label of the button.
      • getListeners

        public <T extends EventListener> T[] getListeners(Class<T> listenerType)
        Returns an array of all the objects currently registered as FooListeners upon this Button. FooListeners are registered using the addFooListener method.

        You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a Button b for its action listeners with the following code:

        ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));
        If no such listeners exist, this method returns an empty array.
        Overrides:
        getListeners in class Component
        Parameters:
        listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
        Returns:
        an array of all objects registered as FooListeners on this button, or an empty array if no such listeners have been added
        Throws:
        ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
        Since:
        1.3
        See Also:
        getActionListeners()
      • processEvent

        protected void processEvent(AWTEvent e)
        Processes events on this button. If an event is an instance of ActionEvent, this method invokes the processActionEvent method. Otherwise, it invokes processEvent on the superclass.

        Note that if the event parameter is null the behavior is unspecified and may result in an exception.

        Overrides:
        processEvent in class Component
        Parameters:
        e - the event
        Since:
        JDK1.1
        See Also:
        ActionEvent, processActionEvent(java.awt.event.ActionEvent)
      • processActionEvent

        protected void processActionEvent(ActionEvent e)
        Processes action events occurring on this button by dispatching them to any registered ActionListener objects.

        This method is not called unless action events are enabled for this button. Action events are enabled when one of the following occurs:

        • An ActionListener object is registered via addActionListener.
        • Action events are enabled via enableEvents.

        Note that if the event parameter is null the behavior is unspecified and may result in an exception.

        Parameters:
        e - the action event
        Since:
        JDK1.1
        See Also:
        ActionListener, addActionListener(java.awt.event.ActionListener), Component.enableEvents(long)
      • paramString

        protected String paramString()
        Returns a string representing the state of this Button. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
        Overrides:
        paramString in class Component
        Returns:
        the parameter string of this button
      • getAccessibleContext

        public AccessibleContext getAccessibleContext()
        Gets the AccessibleContext associated with this Button. For buttons, the AccessibleContext takes the form of an AccessibleAWTButton. A new AccessibleAWTButton instance is created if necessary.
        Specified by:
        getAccessibleContext in interface Accessible
        Overrides:
        getAccessibleContext in class Component
        Returns:
        an AccessibleAWTButton that serves as the AccessibleContext of this Button
        Since:
        1.3

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/button.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut