I have a JComboBox where the user can choose from 94 different options, represented by strings, which correspond to 94 different classes.
All the 94 classes inherit from one parent class, called AbstractTiling. After Choosing one of those options (Strings from ComboBox) the chosen class should be instantiated. But since there are 94 different possibilites I don't want to use 94 if statements. So I tried it with a hashmap, but this leads to the problem that I still don't know the exact type I want to instantiate, so I can't use the methods that the classes overwrite from the parent class or have that the parent class doesn't.
In the code example there are just two entries in the hasmap as an example. Here is the code:
JComboBox groupscb = new JComboBox(isohedrals);
groupscb.setSelectedIndex(52);
groupscb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int selectedItem = ((JComboBox)arg0.getSource()).getSelectedIndex();
Map <Integer, Object> hm = new HashMap<Integer, Object>();
hm.put(52, new IH52());
hm.put(55, new IH55());
//here I want to instantiate the class, since I don't know it
//I used the parent class. But this keeps me from using the
//child classes methods
AbstractTiling tiling = (AbstractTiling) hm.get(selectedItem);
}
});