Java JButton Create createJButton(String text, String name, ActionListener a)

Here you can find the source of createJButton(String text, String name, ActionListener a)

Description

Creates a JButton with a given text, a given name and a given ActionListener.

License

Open Source License

Parameter

Parameter Description
text The label for the button.
name The name for the button.
a An ActionListener for action performing.

Return

The created .

Declaration

public static JButton createJButton(String text, String name, ActionListener a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.event.ActionListener;

import javax.swing.JButton;

public class Main {
    /**//from   w  w w  .j a  v  a2  s  .c  o  m
     * Creates a {@link JButton} with a given text, a given name and a given
     * ActionListener.
     * 
     * @param text The label for the button.
     * @param name The name for the button.
     * @param a An ActionListener for action performing.
     * @return The created {@link JButton}.    
     */
    public static JButton createJButton(String text, String name, ActionListener a) {

        JButton jb = new JButton(text);
        jb.setName(name);
        jb.addActionListener(a);

        return jb;

    }

    /**
     * Creates a {@link Button} with a given label used as name and an 
     * ActionListener.
     * 
     * @param text The name and label for the button.
     * @param a An ActionListener for action performing.
     * @return The created {@link Button}.
     */
    public static JButton createJButton(String text, ActionListener a) {

        return createJButton(text, text, a);

    }
}

Related

  1. createIconButton(Class klass, String resource, String fallbackText)
  2. createIconButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)
  3. createJButton(Container c, String caption, int x, int y, int width, int height, ActionListener al)
  4. createJButton(final String label, final Font font)
  5. createJButton(String label, Font font)
  6. createLabelButton(String text)
  7. createListButton(Action action)
  8. createNoURLGraphicalButton(String imageName, String alternateText)
  9. createOkCancelPanel(final JButton okBtn, final JButton cancelBtn)