Forums Register Login

vectors continued

+Pie Number of slices to send: Send
Hi, this is Chris Roberts. I got stuck trying to create a new instance of my vector. I am trying to create a vector of shapes and place Cirlce() and Point() inside. I tried to do this by using the following code:



[EJFH: Edited to format code and add UBB CODE tags]



How can I go about doing this part if this isn't correct?
[ September 06, 2004: Message edited by: Ernest Friedman-Hill ]
+Pie Number of slices to send: Send
OK. A statement like

new Point();

is like spitting yer chaw out into th' ocean. You create an object of type Point, but it's lost in the Java heap, and you'll never see it again.

If you want to create an object and then do something with it, you need to hold onto the handle:

Point p = new Point();

Now you can refer to that new Point using the "handle" named p. For instance, you could maybe pass p as an argument to the add() method of Vector...

Please run, don't walk, over here and read the JavaRanch Campfire Story about variables; hopefully it'll help ya out.
+Pie Number of slices to send: Send
Chris, you need to assign the Circle and Point instances to variables like you have for Vector. It might be an idea if you reread your class notes to refresh your memory before continuing.

Jules
+Pie Number of slices to send: Send
Here is an example:


It would be useful to read the Sun Tutorial on Collections and Vector API

Joyce

[ September 06, 2004: Message edited by: Joyce Lee ]
[ September 06, 2004: Message edited by: Ernest Friedman-Hill ]
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 431 times.
Similar Threads
which object can be add into a Vector?
About vectors
Implementing Clones
Bean object in Vector question (confused)
Iterator can safely remove?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:39:21.