• Post Reply Bookmark Topic Watch Topic
  • New Topic

vectors continued  RSS feed

 
Chris Roberts
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!