Here you can find the source of jointButton(JFrame frame, final JButton button)
Parameter | Description |
---|---|
frame | The frame to use |
button | The button to use |
public static void jointButton(JFrame frame, final JButton button)
//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); } } }); } }