Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/a8c263813ca9f07871d2962b269009bb to your computer and use it in GitHub Desktop.
Save ezhov-da/a8c263813ca9f07871d2962b269009bb to your computer and use it in GitHub Desktop.
java собственная группа кнопок
[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