The direct answer is that named constants is the only way to avoid having magic numbers in your code.
But the flip-side is that it is debatable whether magic numbers are harmful or the extent that they are harmful. And in this particular case it is debatable whether these actually qualify as "magic" numbers ... at least, IMO.
Lets illustrate this:
// Alternative #1
private final int PLACE_1_X = 5;
private final int PLACE_1_Y = 5;
...
drawOval(PLACE_1_X, PLACE_1_Y, width, height);
// Alternative #2
drawOval(5, 5, width, height);
Which of these is actually more readable? Does defining named constants (which are most likely at a different point in the source code!) make it easier to understand what is going on? Don't you now have the problem that you have to look in two places not one to understand what a specific drawOval
call is going to draw?
The bottom line is that the "no magic numbers" dogma only really applies when the meaning of the numbers is not self-evident from the context ... or when the number is actually a repeatedly used constant. (Like if we were going to use PLACE_1
lots of times in the same "picture".)
You need to think about the context, not just blindly apply the dogma.