1

I create an object (GPolygon), add it to canvas, i rotate it and then i want to reset the rotation, to come back where started. I look at acm page and there is a method called clear() but i can't acces it, probaly because is protected. Text from http://www-cs-faculty.stanford.edu/~eroberts//jtf/javadoc/complete/acm/graphics/GPolygon.html#clear()

How can i use the method clear() on this object? Here is my Polygon code : Java

    GPolygon patrat=new GPolygon(30,30);
    patrat.setFilled(true);
    patrat.setColor(Color.RED);
    patrat.addVertex(0, 0);
    patrat.addEdge(20, 0);
    patrat.addEdge(0,20);
    add(patrat);
    patrat.rotate(10);

Thank you !

Robin Green
  • 32,079
  • 16
  • 104
  • 187

1 Answers1

0

You can call patrat.rotate(-10) when you want to reset the rotation.

Typically, the way for you to use the protected clear() method is through inheritance (i.e. MyClass extends GPolygon, etc).

Olivia
  • 36
  • 1
  • Yea but i give a simple example, my program take differents angle's at any mouse movement, i cant (i think) implement this with -angle. about the extend i allready myclass entends GraphicProgram, i have to make another class ? – Bogdan Alexandru Jul 01 '13 at 16:11
  • Can you store the initial rotation in a variable at the start of the program? Then, you can call patrat.rotate(startrot); when you wish to reset rotation. – Olivia Jul 01 '13 at 17:35
  • Wihtout seeing code, I'm not sure how you should change your existing program to incorporate inheritance of GPolygon. I would create a class (such as MyPolygon extends GPolygon) which would define the specific behaviors you want in your program (i.e. rotation, color, etc). Then, you can instantiate MyPolygon as an object in your class that extends GraphicProgram. Hope this helps/makes sense! – Olivia Jul 01 '13 at 17:42
  • Yes it does. Thank you very much Olivia. – Bogdan Alexandru Jul 01 '13 at 19:36