How can I copy a polygon. This code doesn't work :-(
Code:if(e.getSource() == Copy){
Polygon copyPolygon = new Polygon(select.xpoints,selected.ypoints,selected.npoints);
copyPolygon.translate(10,10);
triangles.add(copyPolygon);
repaint();
}
Printable View
How can I copy a polygon. This code doesn't work :-(
Code:if(e.getSource() == Copy){
Polygon copyPolygon = new Polygon(select.xpoints,selected.ypoints,selected.npoints);
copyPolygon.translate(10,10);
triangles.add(copyPolygon);
repaint();
}
when you say it doesn't work, what happens? Does it not compile? Does it throw an exception during execution?
Also, is it important that two out of 3 of your parameters use the selected object (selected.ypoints and selected.npoints) while the first parameter uses select (select.xpoints)?
What does "doesn't work" mean?
Code:Polygon copyPolygon = new Polygon(select.xpoints,selected.ypoints,selected.npoints);
This line does, in fact, create a new polygon with the same points and in the same order as selected. Or it would if you corrected the typo: select in the first argument should be selected.
You would think the OP would know how to ask a question given that he always cross posts the questions in other forums as well. This is about the third question that I can remember that has been posted here and at stackoverflow.com.
OP, you are being very rude here by cross-posting without notification or providing links. Please respond to this issue. You will risk being on many ignore lists (including mine) until you change this behavior.
Thanks, it is my mistake. I don't realized the typo :-)
I am sorry, it wont happen again. I don't know that posting to many forums is not allowed, but I have no bad intention doing it. It just that, sometimes I need a response so quickly and with hope that I will get more feedback and I can solve the problem. I am so sorry that this caused inconvenience.