I created a post earlier today but it got marked as DUPLICATE and even after my edit I got no response on it. So I'll be trying to be more specific about just my problem..
info about my class
I've a class called Place which extends a class I call Position which is like the class Point, it has x and y coordinates. And now I create new classes which extends Place, called NamedPlace and DescPlace, it's not much that differ them, just that DescPlace have a description and NamedPlace doesn't..
My problem
I need to create a HashMap that where I can put my created objects into. I tried a hashMap like this HashMap<String, Place> placeMap = new HashMap<>();
This one works fine, but this is gonna be problem when I create a new NamedPlace called Pizza Resturant and later on I add another place called Pizza Resturant. Now I've two different objects with the same key in my HashMap
What i want to do
I've a searchfield where I enter the name, which is the key for my HashMap, and add ALL those object with that name to an ArrayList where I can't go through those objects one by one and change stuff. Like I've done here, but here I use just one arrayList to all, I need to have a HashMap that stores all objects and which I do the search in..
class SearchLis implements ActionListener{
public void actionPerformed(ActionEvent ave){
for(int x = 0; x<placeList.size(); x++){
if(placeList.get(x).getHighlighted()==true){
placeList.get(x).setHighlighted(false);
}
}
String search = searchField.getText();
for(int i = 0; i<placeList.size(); i++){
if(placeList.get(i).getName().equals(search)){
placeList.get(i).setHighlighted(true);
mp.repaint();
}
}