Java JFrame jointButton(JFrame frame, final JButton button)

Here you can find the source of jointButton(JFrame frame, final JButton button)

Description

Allows to relate a frame to a button

License

Open Source License

Parameter

Parameter Description
frame The frame to use
button The button to use

Declaration

public static void jointButton(JFrame frame, final JButton button) 

Method Source Code

//package com.java2s;
/* // w  w  w  .j a  v  a  2s.  co m
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JCheckBox;

import javax.swing.JDialog;

import javax.swing.JFrame;

public class Main {
    /**
     * Allows to relate a frame to a button
     *
     * @param frame The frame to use
     * @param button The button to use
     */
    public static void jointButton(JFrame frame, final JButton button) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                button.setEnabled(true);
            }
        });
    }

    /**
     * Allows to relate a frame to a button and a checkbox
     *
     * @param frame The frame to use
     * @param button The button to use
     * @param check The checkbox to use
     */
    public static void jointButton(JFrame frame, final JButton button, final JCheckBox check) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                if (check.isSelected()) {
                    button.setEnabled(true);
                } else {
                    button.setEnabled(false);
                }
            }
        });
    }

    /**
     * Allows to relate a dialog to a button
     *
     * @param frame The frame to use
     * @param button The button to use
     */
    public static void jointButton(JDialog frame, final JButton button) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                button.setEnabled(true);
            }
        });
    }

    /**
     * Allows to relate a dialog to a button and a checkbox
     *
     * @param frame The jdialog to use
     * @param button The button to use
     * @param check The checkbox to use
     */
    public static void jointButton(JDialog frame, final JButton button, final JCheckBox check) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                if (check.isSelected()) {
                    button.setEnabled(true);
                } else {
                    button.setEnabled(false);
                }
            }
        });
    }
}

Related

  1. inputFiles(JFrame argParent)
  2. installEscapeCloseOperation(final JFrame dialog)
  3. internalizeFrame(JFrame frame)
  4. isAv(JFrame frame)
  5. isVisibleNotMinimized(JFrame frame)
  6. loadImageToFrame(JFrame frame, BufferedImage image)
  7. locateForm(JFrame f, int x, int y, int w, int h)
  8. makeFullScreen(JFrame frame)
  9. makeShaped(final JFrame frame)