Java JButton Settings addButton(ActionListener l, Container container, String name, String cmd)

Here you can find the source of addButton(ActionListener l, Container container, String name, String cmd)

Description

Add a button to a container with the given parameters and action listener.

License

Open Source License

Parameter

Parameter Description
l the listener.
container the container.
name the button name.
cmd the action command.

Declaration

public static void addButton(ActionListener l, Container container, String name, String cmd) 

Method Source Code


//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

import java.awt.Container;

import java.awt.event.ActionListener;
import javax.swing.JButton;

public class Main {
    /**/*from ww w . j av  a  2s . c  o m*/
     * Add a button to a container with the given parameters and
     * action listener.
     *
     * @param l the listener.
     * @param container the container.
     * @param name the button name.
     * @param cmd the action command.
     */
    public static void addButton(ActionListener l, Container container, String name, String cmd) {
        JButton button = new JButton(name);
        button.addActionListener(l);
        button.setActionCommand(cmd);
        container.add(button);
    }
}

Related

  1. addAbstractButtonListeners(AbstractButton b, Object... objs)
  2. addActionListener(ActionListener listener, AbstractButton... buttons)
  3. addActionListeners(AbstractButton button, ActionListener[] listeners)
  4. addActionListenerToButtons(ActionListener l, AbstractButton... components)
  5. addButton(Container component, String text, Icon icon, ActionListener listener, String actionCommand)
  6. addButton(String name, JPanel panel, ActionListener action)
  7. addButtonInPanel(Container component, String text, ActionListener listener)
  8. addButtonToPanel(JPanel panel, Object constraints, String text)