Models of dark matter halos based on statistical mechanics: The classical King model