From antiferromagnetism to d-wave superconductivity in the two-dimensional t-J model