# can i pass a float to drawLine() function

can i pass a float to drawLine() function
###### Who is Participating?

Commented:
If you are happy with using JDK1.2.2, it comes with Graphics2D, which allows you to draw graphics using floating point numbers. all you have to is three things.

1. convert the Graphics object to Graphics2D object, like
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
}

2. Create a new Line2D object and draw it using the g2.

g2.draw(new Line2D.Double(x1, y1, x2, y2));

You can alternatively use Line2D.Float also for floating point numbers.
0

Author Commented:
nothing
0

Commented:
no, you can type cast the float value to int value.

g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);

cheers...
Jerson

0

Author Commented:
i have usedthis method only but i need to be precise
0

Commented:
Why not multiply the values by 10 to the nth power.  For example if you have 1.23, multiply it by 100 to make it 123 then in this case, the decimal places are also considered.

Jerson
0

Commented:
You have to decide which precision you need and then use jerch comments to draw the line.

There is no way to draw a fraction of a point, you can only draw a point or not.

And lines are many points.

Lets say x and y are running from 0.00 to 1.00
than you have to map (0.00,0.00) to 0,0
and 1.00/1.00 to 100/100 ... to be able to draw all possible lines in this range with 2 digit precision.

In extension to jerch's comment, to be more precise round and scale (multiplying by something usefull) your values.

P.S. Give jerch the points he give the answer

0

Author Commented: