Solved

can i pass a float to drawLine() function

Posted on 2000-05-11
7
268 Views
Last Modified: 2012-05-04
can i pass a float to drawLine() function
0
Comment
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
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 124
Unhandled exception type Exception 18 52
java mysql insert application 14 41
wild fly 8 startup error 2 37
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

763 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