Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# can i pass a float to drawLine() function

Posted on 2000-05-11
Medium Priority
272 Views
can i pass a float to drawLine() function
0
Question by:kumarnvs
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

Author Comment

ID: 2799614
nothing
0

LVL 4

Expert Comment

ID: 2799891
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 Comment

ID: 2799942
i have usedthis method only but i need to be precise
0

LVL 4

Expert Comment

ID: 2800161
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

LVL 3

Expert Comment

ID: 2800504
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

LVL 1

Accepted Solution

cssathya earned 150 total points
ID: 2800973
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 Comment

ID: 2809486
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
###### Suggested Courses
Course of the Month4 days, 9 hours left to enroll