Two-dimensional Josephson junction arrays coupled through a high-Q cavity