My code should add 3 Objects of type "Location" to the List "locations" I declared right under
public class myClass extends JFrame {
static List<Location> locations = new ArrayList<Location>();
This is the part that SHOULD add to the List:
locations.add(new Location(new Point(1,1), "Test1", travelLocations.Moon));
locations.add(new Location(new Point(2,2), "Test2", travelLocations.Planet));
locations.add(new Location(new Point(3,3), "Test3", travelLocations.Asteroidfield));
And this is my Location class:
import java.awt.Point;
public class Location {
static Point coordinate;
static String name;
static travelLocations type;
public Location(Point curLoc, String name, travelLocations locType) {
coordinate = curLoc;
locName = name;
type = locType;
}
}
What it does: It adds the Location called "Test3" three times, everytime I add a Location it adds one and overwrites every allready in this List. I know, it looks similar to other questions on Stackoverflow, but I compared them and tried those with similar problems and no solution worked for me. I'm sure it is just a small thing and there is an easy solution, but I can't see it. Thank you in advance.