Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. package connectfour;
  3.  
  4. import connectfour.core.Constants;
  5. import java.awt.Color;
  6. import java.awt.Dimension;
  7. import java.awt.GridLayout;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.JButton;
  11. import javax.swing.JPanel;
  12.  
  13. /**
  14. *
  15. * @author spr
  16. */
  17. public class Connect4Panel extends JPanel {
  18. BoardListener boardListener;
  19. RoundButton[][] buttonBoard;
  20.  
  21. public Connect4Panel() {
  22. super();
  23. initComponents();
  24. }
  25.  
  26. private void initComponents() {
  27. setLayout(new GridLayout(Constants.ROWS, Constants.COLS));
  28. setMinimumSize(new Dimension(500, 500));
  29. setPreferredSize(new Dimension(500, 500));
  30. setBackground(Color.BLUE);
  31.  
  32. boardListener = new BoardListener();
  33. buttonBoard = new RoundButton[6][7];
  34.  
  35. for (int c = 0; c < Constants.COLS; c++) {
  36. for (int r = 0; r < Constants.ROWS; r++) {
  37. RoundButton button = new RoundButton();
  38. button.setVisible(true);
  39. putClientProperty("row", r);
  40. putClientProperty("col", c);
  41. if (r == 0) {
  42. button.addActionListener(boardListener);
  43. }
  44. add(button);
  45. }
  46. }
  47. }
  48.  
  49. private class BoardListener implements ActionListener {
  50.  
  51. @Override
  52. public void actionPerformed(ActionEvent e) {
  53. JButton v = (JButton) e.getSource();
  54. int r = (int) getClientProperty("row");
  55. int c = (int) getClientProperty("col");
  56. }
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement