title: writing a Bingo Game in java
body: <p>I'm totally new to Java and on my second self-project.
  I'm trying to write a bingo game. I know there are some posts about this, but I think that my approach is a little bit different from others', so sorry if it looks redundant. 
  My bingo game is 5x5 matrix with 25 buttons and I labled them from 1~25 just for convenience. I also made a pseudo game board called <strong>grid</strong> variable which is a 5x5 2d Character Array. It's originially filled with 'O's but when I press on one of the buttons, then the corresponding index turns into 'X'. I'm using this <strong>grid</strong> to check for bingos since I thought it would be a lot easier than checking the actual buttons. Below is my code.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import javax.swing.event.*;
  public class exex extends JFrame{
      final int size =5; //5x5 bingo board
      int bingos =0; // how many bingos?
      int count=0; // int value for each btn
      JButton[][] btn = new JButton[size][size]; //actual display of btns (bingo board) 
      char[][] grid = new char[size][size]; // grid to check whether it's bingo or not
      int presscount = 1; // how many times ive pressed
      int row; // row for action event
      int column; // column for action event
      boolean bingo; //check if bingo
      exex(){
          setTitle("Bingo for everyone");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Container pane = getContentPane();
          pane.setLayout(new GridLayout(size,size));//basic board setup
          for(int i=0;i&lt;5;i++){
              for(int j=0;j&lt;5;j++){
              btn[i][j] = new JButton(Integer.toString(count)); //setting buttons 1~25;
              grid[i][j] ='O'; // make a grid board to check bingos
              btn[i][j].addActionListener(new ActionListener(){
                  @Override
                  public void actionPerformed(ActionEvent e){ 
                      isBingo(grid,'X'); // check if grid has any bingos, if it does, then set bingo to true.
                      System.out.print(bingo);
                      if(bingo){
                          bingos++;
                      }
                      System.out.print(bingos);
                      JButton btnR = (JButton)e.getSource();
                      System.out.println(presscount);
                      presscount++;
                      for(int i=0;i&lt;5;i++){
                          for(int j=0;j&lt;5;j++){
                              if(btn[i][j] == btnR){
                                  row = i;
                                  column =j;
                                  grid[row][column]='X'; //set pressed button to 'X' char on my grid(2D char array)
                              }
                              System.out.print(grid[i][j]);
                          }
                          System.out.println("");
                      }
                      System.out.println("-----------");
  
  
                  //Color change when pressed, 
                          btnR.setBackground(Color.YELLOW);
                          btnR.setOpaque(true);
  
  
                  }
              });
              add(btn[i][j]);
              count++;
          }
          System.out.println();
      }
      setSize(500,500);
      setVisible(true);
  
  }
  public void isBingo(char[][] array,char g){
      for(int i=0;i&lt;array.length;i++){
          for(int j=0;j&lt;=i;j++){
              if(array[0][j]==g&amp;&amp;array[1][j]==g&amp;&amp;array[2][j]==g&amp;&amp;array[3][j]==g&amp;&amp;array[4][j]==g){ //check for vertical bingos
                  bingo = true;
              }
              else if(array[i][0]==g&amp;&amp;array[i][1]==g&amp;&amp;array[i][2]==g&amp;&amp;array[i][3]==g&amp;&amp;array[i][4]==g){//check for horizontal bingos
                  bingo = true;
              }
              else if(array[0][0]==g&amp;&amp;array[1][1]==g&amp;&amp;array[2][2]==g&amp;&amp;array[3][3]==g&amp;&amp;array[4][4]==g){ //check for S.E diagonal bingos
                  bingo =true;
              }
              else if(array[0][4]==g&amp;&amp;array[1][3]==g&amp;&amp;array[2][2]==g&amp;&amp;array[3][1]==g&amp;&amp;array[4][0]==g){ //check for S.W diagonal bingos
                  bingo= true;
              }
              else // if no bingos, remains false
                  bingo = false;
          }
      }   
  }
  
  public static void main(String[] args) {
      new exex();
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So the problem is if I make one bingo in any direction, then I'm not sure how to count the next bingos I make. Since a bingo in any direction will set my <strong><em>boolean bingo</em></strong>  to true and it will remain true as long as there is a bingo... any additional bingos will not be counted.. How would I fix this? 
  I know the code is really messy and is not well written. Any help is appreciated. </p>