hashtable problem

R

Ralf Bednarz

I have some problems with store and retrieve instance from a hashtable


I create an instance of a java3d class with newInstance() and store this
object in a hastable with the class name as the key.
When I try to get this object from the hashtable, all textures I load in the
java3d class except one are not displayed.

// source[0] = string that represents the name of the class
// instanceHash = Hashtable where I put the instances
// pluginInstance = Object which contains the created instance

if(instanceHash.containsKey(source[0]))
{
pluginInstance = instanceHash.get((String)source[0]);
}else
{
pluginInstance = pluginClass.newInstance();
instanceHash.put((String)source[0],pluginInstance);
}
getContentPane().add( (Container) pluginInstance,BorderLayout.CENTER);
validate();


I can load the class as often as I want but the textures are not displayed
execpt one and that is the same all the times.
The same problem appears when I do this action with a Vector instead of
Hashtable.

Hope you can help me


thanks
Ralf
 
R

Roedy Green

When I try to get this object from the hashtable, all textures I load in the
java3d class except one are not displayed.

You do understand that keys must be unique. You can store at most one
thing under each key. If you want to store multiple things, you need
to store sort of collection object associated with each key, e.g. an
ArrayList.

see http://mindprod.com/jgloss/hashtable.html for the basics.
 
R

Ralf Bednarz

Roedy Green said:
You do understand that keys must be unique. You can store at most one
thing under each key. If you want to store multiple things, you need
to store sort of collection object associated with each key, e.g. an
ArrayList.

see http://mindprod.com/jgloss/hashtable.html for the basics.

That is not what I meant.

I have a java3d class where I use multiple textured objects (cone , sphere
etc.)
these classes can be loaded in my GUI through a dynamic class loading
process.
(the java3d class is extended from JPanel and so I integrate the class as an
Panel in my JFrame)

Not to create a new instance of my java3d class everytime I load it new
(because I can also load different classes. it is like a plugin mechanism)
I want to put the instance of this class in a Hashtable with the class name
as the key (an the names are unique of course).
But now when I load the instance twice the objects (cone sphere ) aren't
textured anymore.

That is the freaky behavior I don't understand, because I only store a
reference of a class in a Hashtable.

I hope this brings you closer to my problem.


thanks
Ralf


 
S

Steve Horsley

I have some problems with store and retrieve instance from a hashtable


I create an instance of a java3d class with newInstance() and store this
object in a hastable with the class name as the key.
When I try to get this object from the hashtable, all textures I load in the
java3d class except one are not displayed.

// source[0] = string that represents the name of the class
// instanceHash = Hashtable where I put the instances
// pluginInstance = Object which contains the created instance

if(instanceHash.containsKey(source[0]))
{
pluginInstance = instanceHash.get((String)source[0]);
}else
{
pluginInstance = pluginClass.newInstance();
instanceHash.put((String)source[0],pluginInstance);
}
getContentPane().add( (Container) pluginInstance,BorderLayout.CENTER);
validate();


I can load the class as often as I want but the textures are not displayed
execpt one and that is the same all the times.
The same problem appears when I do this action with a Vector instead of
Hashtable.


I'm not sure that it makes sense to add multiple Containers to the CENTER
of a BorderLayout. I suspect that you may only ever see the first or last
one added. I think they just overlay each other.

Steve
 
J

Joona I Palaste

Steve Horsley said:
I have some problems with store and retrieve instance from a hashtable
I create an instance of a java3d class with newInstance() and store this
object in a hastable with the class name as the key.
When I try to get this object from the hashtable, all textures I load in the
java3d class except one are not displayed.

// source[0] = string that represents the name of the class
// instanceHash = Hashtable where I put the instances
// pluginInstance = Object which contains the created instance

if(instanceHash.containsKey(source[0]))
{
pluginInstance = instanceHash.get((String)source[0]);
}else
{
pluginInstance = pluginClass.newInstance();
instanceHash.put((String)source[0],pluginInstance);
}
getContentPane().add( (Container) pluginInstance,BorderLayout.CENTER);
validate();


I can load the class as often as I want but the textures are not displayed
execpt one and that is the same all the times.
The same problem appears when I do this action with a Vector instead of
Hashtable.
I'm not sure that it makes sense to add multiple Containers to the CENTER
of a BorderLayout. I suspect that you may only ever see the first or last
one added. I think they just overlay each other.

Which might also be why T-shirts don't have a size called "XM". =)

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen
 
R

Ralf Bednarz

Steve Horsley said:
I have some problems with store and retrieve instance from a hashtable


I create an instance of a java3d class with newInstance() and store this
object in a hastable with the class name as the key.
When I try to get this object from the hashtable, all textures I load in the
java3d class except one are not displayed.

// source[0] = string that represents the name of the class
// instanceHash = Hashtable where I put the instances
// pluginInstance = Object which contains the created instance

if(instanceHash.containsKey(source[0]))
{
pluginInstance = instanceHash.get((String)source[0]);
}else
{
pluginInstance = pluginClass.newInstance();
instanceHash.put((String)source[0],pluginInstance);
}
getContentPane().add( (Container) pluginInstance,BorderLayout.CENTER);
validate();


I can load the class as often as I want but the textures are not displayed
execpt one and that is the same all the times.
The same problem appears when I do this action with a Vector instead of
Hashtable.


I'm not sure that it makes sense to add multiple Containers to the CENTER
of a BorderLayout. I suspect that you may only ever see the first or last
one added. I think they just overlay each other.

Steve

I remove the old one before I add the new

getContentPane().remove((Container)pluginInstance);

and i can even try

getContentPane().removeAll();

but that doesnt't makes it better in any way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top