Results 1 to 2 of 2
Thread: Vector empty item?
- 12-07-2010, 11:09 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Vector empty item?
Hi all,
I'm new here and I'm new to Java.
I'm working on a Java project for school. I want to use a Vector to store the positions of the cars, this works very good, until I need to remove a car..
To save memory en keep it running smooth, I want to remove a car when it rides offscreen, so I build a check like this:
p is the Point I got from the vector (using a for-loop starting at int i = 0)Java Code:if(p.x > 200) { cars.removeElementAt(0); }
But once the first car is removed, the applet stops working, no crash or something, the screen just isn't refreshed or something..
to draw I use this:
I searched on google, and they say everywhere, that all items get shifted back when you remove an item from a Vector, so I guess it should work, also the != null check doesn't seem to work...Java Code:int size = cars.size(); for(int i = 0; i < size; i++) { if(cars.get(i) != null) { Point p = (Point)cars.get(i); g.drawRect(p.x, p.y, 4, 2); } }
I hope you understand my story and that someone can tell me where it goes wrong, if you need more information, just ask please :)
Sorry for my English btw...
- 12-07-2010, 11:20 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
tootip for each item (comboBox)
By justlynn in forum NetBeansReplies: 5Last Post: 07-29-2010, 03:20 PM -
Add item to combobox permanently
By efozdel in forum New To JavaReplies: 18Last Post: 07-10-2010, 11:30 PM -
Add JList item from resultset
By mine0926 in forum NetBeansReplies: 1Last Post: 06-17-2010, 09:47 AM -
Vector<vector> loop thru
By ocean in forum New To JavaReplies: 11Last Post: 11-21-2009, 02:17 PM -
Remove an item from listbox
By Dieter in forum Advanced JavaReplies: 9Last Post: 09-21-2009, 10:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks