The five phase changes of matter are solids, liquids, gases, plasmas and Bose-Einstein condensates. Elements are able to move between these phases when certain physical conditions exist.
In the instance of a glass of water, the H20 is in a liquid state. As it heats up, the molecules become excited and move around a lot. Eventually, the water will become a gas. The physical conditions that are present cause the phase to change. Adding energy will cause the matter to increase in phase. For instance, a solid will become a liquid, liquid will become gas, etc. Adding energy will not cause it to revert to a lower phase. Removing energy from it will cause it to go from liquid to solid, for example. Water heating up and then hitting cooler air, such as on the outside of a glass, will cause it to condense into water droplets again.