Question: Create a java Swing program which allows the user to draw a polygon. You will need to implement the interfaces MouseListener and ActionListener. A frame
Create a java Swing program which allows the user to draw a polygon. You will need to implement the interfaces MouseListener and ActionListener.
A frame or panel should display two buttons: "Draw Polygon" and "Clear"
The user should be able to click any numbertof points on the window and then "Draw Polygon". The GUI should draw a polygon based on the coordinates of where the user clicked.
The user should be able to click "Clear" and the polygon is no longer displayed. The user should then be able to draw a new polygon.
There are many ways to implement this however one might be to make an empty Polygon object in your class. Once you have a Polygon object you can use the addPoint method after a mouse event.
You might find my Pointillism class in GraphicsExample.java darr helpful because it also uses mouse click locations and draws shapes.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
