I am doing a sticky note program for myself and I have a JPopupMenu with a hide command in each note. I want to take advantage of the new translucency in Java 6 Update N. The translucency method takes a float value so I need to iterate from 0.9f to 0.0f in a loop. I did it like so with an ArrayList of the values except I think this is a dumb way of doing it. The code runs smoothly and it give that exact desired effect. Is there any way to iterate through float values 9 to 0 without first adding those values to an ArrayList?
Unfortunately I don't know of a more elegant solution. Some Basic dialects had for loops where you could give a step width for this.
Perhaps you could refactor this code to a separate method which generates the sequence of values. But then you'd have to use an iterator or something with another loop. Don't know which one is better. Anyway I hope it's working...
Originally posted by Paul Clapham: So it runs one time fewer than what you expected.
Thank you, Paul. Tricky. Using integers surely better, better precision and simple. Atleast doubles will give all 10 steps, but then they have to be converted to float and 1.3877788E-16 is not quite a 0.0.