Question: user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user.
user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user. If the user does not chose to draw with a gradient, then Paint with a solid color of the st Color. The following code can create a gradient paint object:
Paint paint new GradientPaint color color true;
To set the stroke for a line to be drawn, you can use the following code:
if dashCheckBoxisSelected
stroke new BasicStrokelineWidth BasicStroke.CAPROUND, BasicStroke.JOINROUND, dashLength, ;
else
stroke new BasicStrokelineWidth BasicStroke.CAPROUND, BasicStroke.JOINROUND;
Where the first stroke line creates a dashed line and dashLength is a one element float array with the dash length in the first element. The second stroke line creates an undashed line with the line width specified from the GUI.
Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.
A template project has been provided for you in Canvas in JavaDDrawingApplicationTemplate.zip. This project contains a MyShapes hierarchy that is a complete shape hierarchy for drawing a line, rectangle or oval. You must use this MyShapes hierarchy. A template for the Drawing Application Frame is also provided along with a template for the DrawPanel inner class. You do not need to use these templates if you so choose.
In the paintComponentGraphics g method of the DrawPanel, to loop through and draw each shape created by the user, you will loop through an ArrayList of MyShapes, that you built, and call the drawGraphicsD gd method for each shape. The draw method is already implemented in the MyShapes hierarchy.
Note: You do not need to create an event handler for each component in the top two lines of the frame. You only need to create event handlers for the buttons. You can get the values out of all the other components in the top two lines, when the user presses the mouse button o
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
