Hi I'm trying to draw a line in java using g.drawLine

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


im trying to draw this :
g.drawLine (xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7), yCenter + 200 * Math.sin(2 * Math.PI * 3 / 7), 70 ,336);


but that above is (double, double, int, int)

I made a cast for Math.PI like :
int pi = (int) Math.PI;
this worked

I then tried to do
int cos = (int) Math.cos;
this did not work

so i still get a (double, double, int, int) and g.drawLine wont compile that.
any ideas on how to fix? thanks!!!!

Recommended Answers

All 3 Replies

note xCenter and yCenter were both suppose to equal 250

In this case you should cast the result of the evaluation of "xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)" or "yCenter + 200 * Math.sin(2 * Math.PI * 3 / 7)":

g.drawLine ((int)(xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)),(int)(yCenter + 200 * Math.sin(2 * Math.PI * 3 / 7)), 70 ,336);

That worked, although it didn't draw anything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.