In this note the Lagrangian function for the electromagnetic field of a cavity resonator is found. And from this Lagrangian is deduced a perturbation formula which includes Müller's celebrated result as a special case. The same perturbation formula is derived also from the Boltzmann-Ehrenfest adiabatic theorem in a most simple manner