Last active
March 10, 2019 12:20
-
-
Save ezhov-da/a8c263813ca9f07871d2962b269009bb to your computer and use it in GitHub Desktop.
java собственная группа кнопок
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[code:]java[:code] | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.logging.Logger; | |
import javax.swing.AbstractButton; | |
/** | |
* | |
* @author ezhov_da | |
*/ | |
public class JEButtonGroup implements ActionListener | |
{ | |
private static final Logger LOG = Logger.getLogger(JEButtonGroup.class.getName()); | |
private final List<AbstractButton> listButtons; | |
private AbstractButton abstractButtonLastSelection; | |
public JEButtonGroup() | |
{ | |
this.listButtons = new ArrayList<AbstractButton>(); | |
} | |
public void addButton(AbstractButton abstractButton) | |
{ | |
listButtons.add(abstractButton); | |
} | |
public void removeButton(AbstractButton abstractButton) | |
{ | |
listButtons.add(abstractButton); | |
} | |
@Override | |
public void actionPerformed(ActionEvent e) | |
{ | |
Object source = e.getSource(); | |
if (source instanceof AbstractButton) | |
{ | |
AbstractButton nowAbstractButton = (AbstractButton) source; | |
if (abstractButtonLastSelection != null && abstractButtonLastSelection != nowAbstractButton) | |
{ | |
abstractButtonLastSelection.setSelected(false); | |
} | |
abstractButtonLastSelection = nowAbstractButton; | |
} | |
} | |
} | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment