Results 1 to 9 of 9
Thread: access array list item from draw
- 04-19-2011, 11:38 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 53
- Rep Power
- 0
access array list item from draw
Hey, iv been struggling trying to access data in an array list object, the array list contains an integer value id like to use to draw on screen so if anyone can tell me how to access it id be very grateful :
The problem is the draw function wont accept imageposx.get() as it is an object type as opposed to a integer, so is there a way to access it or convert it to an integer type to use in the drawimage function?Java Code:ArrayList<Object> imageposx=new ArrayList<Object>(); //instance of the arraylist im using Integer xpositionlist=new Integer(last_X); imageposx.add(xpositionlist); // add last place clicked to the array list //how i am trying to use it g.drawImage(imagefile,imageposx.get(0), 0, null);
- 04-19-2011, 11:50 AM #2
Declare ArrayList<Integer> instead of ArrayList<Object> and autoboxing should take care of it.
And use meaningful variable names that aren't confusing. I can't see any justification for naming an Integer type variable xpositionlist, especially when your List type variable is named imageposx
db
-
it is because you converted it to an Object in the first place...
Java Code:ArrayList<Object> imageposx=new ArrayList<Object>();
that should say ArrayList<Integer> imageposx = new ArrayList<>();
- 04-19-2011, 11:57 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
-
JosAh there was a minute difference between our posts, db's post didnt appear until after I posted mines
- 04-19-2011, 12:07 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
-
It's cool, i was going to post again saying Ah, db beat me to it, but i didn't wanna make it worse lol
- 04-19-2011, 12:23 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 04-19-2011, 12:34 PM #9
Member
- Join Date
- Feb 2011
- Posts
- 53
- Rep Power
- 0
Similar Threads
-
Getting an item from an array
By ile4 in forum New To JavaReplies: 9Last Post: 01-13-2011, 03:42 PM -
Appending and item to a Select List
By Samurai Coder in forum New To JavaReplies: 1Last Post: 12-04-2009, 10:56 PM -
Button to remove item from list
By dacool25 in forum Java AppletsReplies: 6Last Post: 10-14-2009, 04:30 AM -
JSTL - forEach tag with HashSet in its item attribute - How do i access the previouse
By liav.ezer in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-15-2008, 05:45 PM -
linked list nodes all refernce same item.
By yllawwally in forum New To JavaReplies: 0Last Post: 12-18-2007, 08:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks