public void mousePressed(MouseEvent e) {
        final int s = 30; // cell size
        final int x = e.getX() / s;
        final int y = e.getY() / s;
        final int button = e.getButton();

        // clicked outside the board
        if (x < 0 || y < 0 || x > grid.xCells || y > grid.yCells)
            return;

        try {
            if (button == OPEN_CELL_BUTTON)
                grid.openCell(x, y);

            if (button == MARK_MINE_BUTTON)
                grid.markMine(x, y);

            grid.checkGameOver();
        } catch (Exception ignored) {
        }
    }