Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: How many fl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 12 Topic 15906 of 16566
Post > Topic >>

Re: How many float values in range 0f - 1f inclusive?

by "John B. Matthews" <nospam@[EMAIL PROTECTED] > Mar 22, 2008 at 10:15 PM

In article <CygFj.65$z51.55@[EMAIL PROTECTED]
>,
 "Jeff Higgins" <oohiggins@[EMAIL PROTECTED]
> wrote:
[...]
> This all came about because I am using a JSlider control to pick
> values for an java.awt.Color, where the arguments to the Color
> constructor are values between 0f - 1f.  Because JSlider only
> operates with integer values I was using a range of 0 - 10000
> and then multiplying by .0001 to get my float value.  I was trying
> to find a better range of integers to use for my JSlider range
> so that when I display the value I've picked with the slider
> I don't get ugly .50168 or some such for .5.  I guess I'll probably
> be better off dealing with that on the display end using printf or
> decimalFormat or such.

Indeed, you should keep the model (rational approximation of a floating 
point number) separate from the view (meaningful decimal format).

It's also useful to recall that a slider models an analog device: it 
re****ts the ratio of two screen coordinates with a resolution no greater 
than that provided by the mouse, roughly one pixel. Given a slider 1000 
pixels long, the accuracy can never be more than one part in 10^3, 
corresponding to an accuracy of three significant digits (sd). The 
accuracy is pro****tionally less for a shorter slider: Math.floor 
(Math.log10 (length)).

You can "pin" the slider's value to a particular tick size using an 
expression such as Math.rint (value / tickSize) * tickSize. You can 
adjust the tick size according to the slider's longest dimension: say 
0.01 for a 100 to 1000 pixels, and 0.001 for > 1000 pixels.

Would a custom color chooser provide a better abstraction?

<http://java.sun.com/docs/books/tutorial/uiswing/components/colorchooser.
html>

John
-- 
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 




 12 Posts in Topic:
How many float values in range 0f - 1f inclusive?
"Jeff Higgins"   2008-03-22 11:26:54 
Re: How many float values in range 0f - 1f inclusive?
Patricia Shanahan <pat  2008-03-22 09:31:16 
Re: How many float values in range 0f - 1f inclusive?
Alex.From.Ohio.Java@[EMAI  2008-03-22 11:27:56 
Re: How many float values in range 0f - 1f inclusive?
Patricia Shanahan <pat  2008-03-22 11:55:48 
Re: How many float values in range 0f - 1f inclusive?
Lew <lew@[EMAIL PROTEC  2008-03-22 16:34:19 
Re: How many float values in range 0f - 1f inclusive?
"Jeff Higgins"   2008-03-22 19:23:55 
Re: How many float values in range 0f - 1f inclusive?
"John B. Matthews&qu  2008-03-22 22:15:26 
Re: How many float values in range 0f - 1f inclusive?
"Jeff Higgins"   2008-03-24 08:13:54 
Re: How many float values in range 0f - 1f inclusive?
Alex Kizub <akizub@[EM  2008-03-23 06:09:11 
Re: How many float values in range 0f - 1f inclusive?
Patricia Shanahan <pat  2008-03-23 06:53:32 
Re: How many float values in range 0f - 1f inclusive?
Alex.From.Ohio.Java@[EMAI  2008-03-23 07:35:31 
Re: How many float values in range 0f - 1f inclusive?
Patricia Shanahan <pat  2008-03-23 08:04:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 15:17:06 CST 2008.