The electromagnetic initial-boundary value problem for a cavity enclosed by perfectly conducting walls is considered. The cavity medium is defined by its permittivity and permeability which vary continuously in space. The electromagnetic field comes from a source in the cavity. The field is described by a magnetic vector potential A satisfying a wave equation with initial-boundary conditions. This description through A is rigorously shown to give a unique solution of the problem and is the starting point for numerical computations. A Chebyshev collocation solver has been implemented for a cubic cavity, and it has been compared to a standard finite element solver. The results obtained are consistent while the collocation solver performs substantially faster. Some time histories and spectra are computed.