public class GameData {
  public boolean started;
  public int score;
  public Square[][]board;
  
  public GameData() {
    started = false;
    score = 0;
    board = new Square[8][8];
  }
}
Java2html

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class GUI extends JFrame implements ActionListener {
  private JButton startButton = new JButton("Start");
  private JLabel scoreLabel = new JLabel("Score: 0");
  private JPanel boardPanel = new JPanel(new GridLayout(8,8));
  private TheGame game = new TheGame();
  public GUI() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400300);
    setTitle("JSameGame");
    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(startButton,BorderLayout.WEST);
    topPanel.add(scoreLabel,BorderLayout.EAST);
  
    startButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        if game.data.started ) {
          int value = JOptionPane.showConfirmDialog(null, "Are you sure?");
          if value == JOptionPane.OK_OPTION ) {
            scoreLabel.setText("Score: 0");
            game.initializeGame();
            updateBoard();            
          }
        else {
          scoreLabel.setText("Score: 0");
          game.initializeGame();
          updateBoard();
        }
      }
    });
    
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(topPanel,BorderLayout.NORTH);
    getContentPane().add(boardPanel);
    setLocationRelativeTo(null);
  }
  private void updateBoard() {
    boardPanel.removeAll();
    int cellNum = 0;
    for int i = 0; i < 8; i++ ) {
      for int j = 0; j < 8; j++ ) {
        JButton cellButton = new JButton();
        cellButton.setOpaque(true);
        cellButton.setActionCommand(cellNum+"");
        switch (game.data.board[i][j].color) {
          case Square.EMPTY: cellButton.setBackground(Color.BLACK);break;
          case Square.BLUE: cellButton.setBackground(Color.BLUE);break;
          case Square.RED: cellButton.setBackground(Color.RED);break;
          case Square.GREEN: cellButton.setBackground(Color.GREEN);break;
          case Square.PINK: cellButton.setBackground(Color.PINK);break;
        }
        cellButton.addActionListener(this);
        boardPanel.add(cellButton);
        cellNum++;
      }
    }
    boardPanel.updateUI();
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    game.data.started = true;
    int cell = Integer.parseInt(e.getActionCommand());
    int x = cell / 8;
    int y = cell % 8;
    game.squareSelected(x, y);
    updateBoard();
    scoreLabel.setText("Score: "+game.data.score);
    if game.isBoardEmpty() ) {
      JOptionPane.showMessageDialog(this, "You WIN!\nYour Score is "+game.data.score+"\nPress OK to start a new Game");
      game.data.started = false;
      startButton.doClick();
    }else{
      if !game.isPairsAvailable() ) {
        JOptionPane.showMessageDialog(this, "You LOSE!\nYour Score is "+game.data.score+"\nPress OK to start a new Game");
        game.data.started = false;
        startButton.doClick();
      }
    }
  }
  public static void main(String[] args) {
    try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())catch(Exception e){}
    new GUI().setVisible(true);
  }
}
Java2html

public class Square {
  public static final int EMPTY = 0;
  public static final int RED = 1;
  public static final int BLUE = 2;
  public static final int GREEN = 3;
  public static final int PINK = 4;
  
  public int x;
  public int y;
  public int color;
  
  public Square(int x, int y, int color) {
    this.x = x;
    this.y = y;
    this.color = color;
  }
}
Java2html

import java.util.Random;
public class TheGame {
  private int pointsFactor;
  private int currentColor;
  private Random rand = new Random();
  public GameData data = new GameData();
  public void initializeGame() {
    data.started = false;
    data.score = 0;
    for int i = 0; i < 8; i++ ) {
      for int j = 0; j < 8; j++ ) {
        data.board[i][jnew Square(i,j,rand.nextInt(4) );
      }
    }
  }
  public void squareSelected(int x, int y) {
    if data.board[x][y].color != Square.EMPTY ) {
      Square tmpSquare = data.board[x][y];
      boolean foundSameColor = ( ( ( tmpSquare.x > && data.boardtmpSquare.x - ][tmpSquare.y].color == tmpSquare.color ) ) ||
          ( ( tmpSquare.x < && data.boardtmpSquare.x + ][tmpSquare.y].color == tmpSquare.color ) ) || 
          ( ( tmpSquare.y > && data.board[tmpSquare.x][ tmpSquare.y - ].color == tmpSquare.color ) ) ||
          ( ( tmpSquare.y < && data.board[tmpSquare.x][ tmpSquare.y + ].color == tmpSquare.color ) ) );
      if foundSameColor ) {
        currentColor = tmpSquare.color;
        tmpSquare.color = Square.EMPTY;
        pointsFactor = 1;
        calculatePoints(tmpSquare);
        data.score += ( ( pointsFactor - pointsFactor - ) );
        pointsFactor = 0;
        applyGravity();
        applyWind();
      }
    }
  }
  public void calculatePoints(Square currentSquare) {
    if currentSquare.x > ) {
      if data.boardcurrentSquare.x - ][currentSquare.y].color == currentColor ) {
        pointsFactor++;
        data.boardcurrentSquare.x - ][currentSquare.y].color = Square.EMPTY;
        calculatePoints(data.boardcurrentSquare.x - ][currentSquare.y]);
      }
    }
    if currentSquare.x < ) {
      if data.boardcurrentSquare.x + ][currentSquare.y].color == currentColor ) {
        pointsFactor++;
        data.boardcurrentSquare.x + ][currentSquare.y].color = Square.EMPTY;
        calculatePoints(data.boardcurrentSquare.x + ][currentSquare.y]);
      }      
    }
    if currentSquare.y > ) {
      if data.board[currentSquare.x][ currentSquare.y - 1].color == currentColor ) {
        pointsFactor++;
        data.board[currentSquare.x][ currentSquare.y - 1].color = Square.EMPTY;
        calculatePoints(data.board[currentSquare.x][ currentSquare.y - 1]);
      }      
    }
    if currentSquare.y < ) {
      if data.board[currentSquare.x][ currentSquare.y + 1].color == currentColor ) {
        pointsFactor++;
        data.board[currentSquare.x][ currentSquare.y + 1].color = Square.EMPTY;
        calculatePoints(data.board[currentSquare.x][ currentSquare.y + 1]);
      }      
    }
  }
  private void applyGravity() {
    for int y = 0; y < 8; y++ ) {
      int floor = -1;
      for int x = 7; x >= 0; x--) {
        if data.board[x][y].color == Square.EMPTY ) {
          if floor == -) {
            floor = x;
          }
        else {
          if floor != -) {
            data.board[floor][y].color = data.board[x][y].color;
            data.board[x][y].color = Square.EMPTY;
            floor--;
          }
        }
      }
    }
  }
  public void applyWind() {
    for int i = 0; i < 8; i++ ) {
      for int y = i; y < 8; y++ ) {
        boolean empty = true;
        for int x = 0; x < 8; x++ ) {
          if data.board[x][y].color != Square.EMPTY )
            empty = false;
        }
        if empty ) {
          for int xx = 0; xx < 8; xx++ ) {
            for int yy = y; yy >= 0; yy-- ) {
              if yy == ) {
                data.board[xx][yy].color = Square.EMPTY;
              else {
                data.board[xx][yy].color = data.board[xx][yy-1].color;
              }
            }
          }
        }
      }
    }
  }
  public boolean isBoardEmpty() {
    for int i = 0; i < 8; i++ ) {
      for int j = 0; j < 8; j++ ) {
        if data.board[i][j].color != Square.EMPTY )
          return false;
      }
    }
    return true;
  }
  public boolean isPairsAvailable() {
    for int i = 0; i < 8; i++ ) {
      for int j = 0; j < 8; j++ ) {
        if ( ( i < && data.board[i][j].color != Square.EMPTY && data.board[i][j].color == data.board[i+1][j].color ) ) {
          return true;
        }
        if ( ( j < && data.board[i][j].color != Square.EMPTY && data.board[i][j].color == data.board[i][j+1].color ) ) {
          return true;
        }
      }
    }
    return false;
  }
}
Java2html