Iwin Posted October 27, 2016 Share Posted October 27, 2016 I'm currently working on a area plotter. Simply, you click on the screen.. it adds the location (X, Y, Z) into an ArrayList.. ArrayList<Position> areaList = new ArrayList<>(); But to visually see the area.. you have to convert the arraylist into an Area Example: Area chickenArea = new Area(new Position[] { new Position(3171, 3289, 0), new Position(3169, 3291, 0), new Position(3169, 3294, 0), new Position(3170, 3295, 0), new Position(3170, 3298, 0), new Position(3169, 3299, 0), new Position(3173, 3303, 0), new Position(3173, 3307, 0), new Position(3179, 3307, 0), new Position(3180, 3303, 0), new Position(3182, 3303, 0), new Position(3184, 3302, 0), new Position(3185, 3300, 0), new Position(3186, 3298, 0), new Position(3186, 3295, 0), new Position(3185, 3290, 0), new Position(3183, 3289, 0), new Position(3178, 3289, 0), new Position(3177, 3288, 0), new Position(3174, 3288, 0), }); If you just use the arraylist to draw a tile, it only plots those specific locations.Any and all help is greatly appreciated Quote Link to comment Share on other sites More sharing options...
Precise Posted October 27, 2016 Share Posted October 27, 2016 so you want to make the arraylist of positions into an array, to be passed into the instance of the area? if so, just do this and change the object type to Position instead of String : http://stackoverflow.com/questions/4042434/converting-arrayliststring-to-string-in-java 1 Quote Link to comment Share on other sites More sharing options...
Explv Posted October 27, 2016 Share Posted October 27, 2016 (edited) I'm currently working on a area plotter. Simply, you click on the screen.. it adds the location (X, Y, Z) into an ArrayList.. ArrayList<Position> areaList = new ArrayList<>(); But to visually see the area.. you have to convert the arraylist into an Area Any and all help is greatly appreciated List<Position> posList = new ArrayList<>(); Position[] positions = posList.toArray(new Position[posList.size()]); Or List<Position> posList = new ArrayList<>(); Position[] positions = posList.stream().toArray(Position[]::new); Edited October 27, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Iwin Posted October 27, 2016 Author Share Posted October 27, 2016 List<Position> posList = new ArrayList<>(); Position[] positions = posList.toArray(new Position[posList.size()]); Or List<Position> posList = new ArrayList<>(); Position[] positions = posList.stream().toArray(Position[]::new); For some reason I get this result :| Quote Link to comment Share on other sites More sharing options...
Explv Posted October 27, 2016 Share Posted October 27, 2016 For some reason I get this result :| If you just want to create a rectangular area then you should use the: Area(int x1, int y1, int x2, int y2) Constructs a rectangular area using x and y coordinates from two separate positions. Or Area(Position southWest, Position northEast) Constructs a rectangular area using two positions Constructors. Quote Link to comment Share on other sites More sharing options...
Iwin Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) Got it! Thank you very much! Position[] positions = posList.stream().toArray(Position[]::new); Area test = new Area(positions); for (Position p : test.getPositions()) { drawTile(this, g, p, Color.GREEN, Color.WHITE, ""); } Edited October 27, 2016 by Iwin Quote Link to comment Share on other sites More sharing options...
Alek Posted October 27, 2016 Share Posted October 27, 2016 Every time you add or remove a position from that area, you should be reconstructing that Area using the new positions in the list (after converting to an array). Or is your issue converting from a list to an array? Quote Link to comment Share on other sites More sharing options...
Iwin Posted October 27, 2016 Author Share Posted October 27, 2016 Every time you add or remove a position from that area, you should be reconstructing that Area using the new positions in the list (after converting to an array). Or is your issue converting from a list to an array? My issue was converting: ArrayList<Position> posList = new ArrayList<>(); To an Area. but as posted above, my issue was solved. Unless this can be make more efficient (which is more than welcome) Quote Link to comment Share on other sites More sharing options...
Alek Posted October 27, 2016 Share Posted October 27, 2016 Ah I see; nope you got some good suggestions. Good luck with your tool! Quote Link to comment Share on other sites More sharing options...