Solved

can i pass a float to drawLine() function

Posted on 2000-05-11
7
264 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now