As amassoscillates on a spring, so do the potential and kinetic energy, while their sum (mechanical energy)保持不变。
In the case of a horizontal spring:
The situation is conceptually slightly different for a vertical spring. Here the potential energy is the sum of gravitational and elastic energy. However, if one measures the displacement from the 'new' mass equilibrium position (and not from the unloaded spring equilibrium position), the same considerations as the horizontal case apply.