Solved

can i pass a float to drawLine() function

Posted on 2000-05-11
7
266 Views
Last Modified: 2012-05-04
can i pass a float to drawLine() function
0
Comment
Question by:kumarnvs
7 Comments
 

Author Comment

by:kumarnvs
ID: 2799614
nothing
0
 
LVL 4

Expert Comment

by:jerch
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

by:kumarnvs
ID: 2799942
i have usedthis method only but i need to be precise
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 4

Expert Comment

by:jerch
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

by:falter
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.

You have to adjust your coordinate system to this.

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

by:
cssathya earned 50 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

by:kumarnvs
ID: 2809486
Thanks for the answers.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question