Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package connectfour;
- import connectfour.core.Constants;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JPanel;
- /**
- *
- * @author spr
- */
- public class Connect4Panel extends JPanel {
- BoardListener boardListener;
- RoundButton[][] buttonBoard;
- public Connect4Panel() {
- super();
- initComponents();
- }
- private void initComponents() {
- setLayout(new GridLayout(Constants.ROWS, Constants.COLS));
- setMinimumSize(new Dimension(500, 500));
- setPreferredSize(new Dimension(500, 500));
- setBackground(Color.BLUE);
- boardListener = new BoardListener();
- buttonBoard = new RoundButton[6][7];
- for (int c = 0; c < Constants.COLS; c++) {
- for (int r = 0; r < Constants.ROWS; r++) {
- RoundButton button = new RoundButton();
- button.setVisible(true);
- putClientProperty("row", r);
- putClientProperty("col", c);
- if (r == 0) {
- button.addActionListener(boardListener);
- }
- add(button);
- }
- }
- }
- private class BoardListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- JButton v = (JButton) e.getSource();
- int r = (int) getClientProperty("row");
- int c = (int) getClientProperty("col");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement