I draw many triangle polygons and store it in Linked List. My problem is that, when I store the drawing in a Notepad file, the data is unreadable (weird symbol). When I try to print it using println the output is like this java.awt.Polygon@1d6096.
How to store the coordinate of the polygon in Notepad?
...
java.util.List<Polygon> triangles = new LinkedList<Polygon>();
String pathname = "eyemovement.txt";
...
int[] xs = { startDrag.x, endDrag.x, midPoint.x };
int[] ys = { startDrag.y, startDrag.y, midPoint.y };
triangles.add(new Polygon(xs, ys,3));
...
public void actionPerformed(ActionEvent e) {
if(e.getSource() == saveBtn){
try {
FileOutputStream fos = new FileOutputStream(pathname);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(triangles);
oos.flush();
oos.close();
fos.close();
}
catch (Exception ex) {
System.out.println("Trouble writing display list vector");
}
}
EDITED:
I have tried all the suggestions but still I can't managed to get the output as the following. I have tried the "Printwriter" as well, but I cant solved the problem. Help me, please, my head is so heavy with this :-(
I draw the triangles, make changes, and store it in Linked List. After finished drawing, and make changes, I click save button and save it in Notepad.txt with hope that I will get the output in Notepad like this:
40 60 50 this line represents vertices Xs of triangle 1
40 40 50 this line represents vertices Ys of triangle 1
60 80 70 triangle 2
60 60 70
100 120 110 triangle 3
100 100 110