Results 1 to 9 of 9
- 04-19-2010, 12:23 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
how do you make comparison between vectors?
code i try is like
i am not sure about the red bit,Java Code:if (getVelocity() [COLOR="Red"]equals (20.0, 0.0))[/COLOR]{ setBodyImage(new BodyImage("st1mob2walkR.gif"));
however I used system println for getVelocity(), which shows on the terminal are vectors (20.0,0.0)[I also check the doc.]
what should I do to make the red bit working as I was intended?
-
The Vector (or better its parent, AbstractList) API has important information about the equals method that is pertinent here. But having said that, the amateur physicist in me makes me think that this Vector holds velocity information, and that you'll want to set your body image to a "walking(?)" image if the speed is > something and < something else. If so then your approach will need to change.
- 04-19-2010, 12:40 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
-
- 04-19-2010, 01:00 AM #5
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
-
You can't compare a Vector to a double but rather only to another Vector. In fact that's one of the basic rules when using the equals method: you can only compare one object with another object of the same class.
- 04-19-2010, 01:22 AM #7
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
-
- 04-19-2010, 01:53 AM #9
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
do those doubles exist in the constructor?
i don't know this class specifically but wouldn't something like
vector1.equals(new Vector(double1, double2));
work
??
yeah uhm, i just looked at the api for vector and it's kind of strange, suggest you do what fub suggested, read that api front and back, and the class it extends from.Last edited by Cruncher; 04-19-2010 at 02:00 AM.
Similar Threads
-
String Comparison
By evant8950 in forum Java AppletsReplies: 6Last Post: 04-22-2009, 08:11 AM -
Vectors of Vectors or hash-somethings?
By mindwarp in forum New To JavaReplies: 3Last Post: 03-10-2008, 02:57 PM -
Comparison of Strings
By Cero.Uno in forum New To JavaReplies: 3Last Post: 02-11-2008, 02:46 AM -
Date comparison
By Rageagainst20 in forum New To JavaReplies: 0Last Post: 12-19-2007, 06:34 PM -
String comparison
By sireesha in forum New To JavaReplies: 1Last Post: 12-18-2007, 12:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks