Java poker implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GamePanel.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
  3. *
  4. * This code may not be redistributed without prior permission from the
  5. * aforementioned copyright holder(s).
  6. */
  7. package com.md87.cardgame.config;
  8. import com.md87.cardgame.config.games.GameInfo;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. import java.util.Map;
  14. import javax.swing.JPanel;
  15. import javax.swing.JRadioButton;
  16. import javax.swing.JSeparator;
  17. import net.miginfocom.swing.MigLayout;
  18. /**
  19. *
  20. * @author Chris
  21. */
  22. public class GamePanel extends JPanel implements ActionListener {
  23. private static final long serialVersionUID = 1;
  24. private final Map<GameInfo, JRadioButton> games = new HashMap<GameInfo, JRadioButton>();
  25. private final ConfigScreen owner;
  26. public GamePanel(final ConfigScreen owner) {
  27. this.owner = owner;
  28. setLayout(new MigLayout("flowy, fill"));
  29. GameInfo.GameType type = GameInfo.GameType.HOLDEM;
  30. for (GameInfo game : GameInfo.getGames()) {
  31. JRadioButton button = buildButton(game);
  32. if (type != game.getGameType()) {
  33. type = game.getGameType();
  34. add(new JSeparator(), "growx");
  35. }
  36. add(button);
  37. }
  38. }
  39. private JRadioButton buildButton(final GameInfo game) {
  40. final JRadioButton res = new JRadioButton(game.getName());
  41. if (games.size() == 0) {
  42. res.setSelected(true);
  43. owner.setGame(game);
  44. }
  45. res.addActionListener(this);
  46. games.put(game, res);
  47. return res;
  48. }
  49. public void actionPerformed(ActionEvent e) {
  50. for (Map.Entry<GameInfo, JRadioButton> entry : games.entrySet()) {
  51. if (entry.getValue().equals(e.getSource())) {
  52. owner.setGame(entry.getKey());
  53. entry.getValue().setSelected(true);
  54. } else {
  55. entry.getValue().setSelected(false);
  56. }
  57. }
  58. }
  59. }