Answered step by step
Verified Expert Solution
Question
1 Approved Answer
No coding provided but needed help with this one Exercise 2 - Simple Animation (6 points) If you do not complete this exercise during the
No coding provided but needed help with this one
Exercise 2 - Simple Animation (6 points) If you do not complete this exercise during the lab period, you need to complete the work outside of the lab period and bring the completed work to the lab next week. In this exercise, we are going to draw an arrow, pointing up, and animate it... it will move from the bottom of the window to the top that First, we need a class to represent the arrow. The arrow will be a composite class is, it contains two or more classes within it. In our case, besides the canvas on which it is drawn, the arrow will have two visible pieces.. a shaft (a rectangle) and a head (a triangle). To draw the arrow will take two steps, then draw the shaft then draw the head. Similarly for erasing it (erase the head, then the shaft) 1. Write the Arrow class The Arrow class will have the attributes: private Canvas canvas; private Triangle head; private Rectangle shaft; // the canvas on which to dratw // a filled, B&N head // an unfilled, B&W shaft Draw the arrow as an unfilled rectangle (the shaft) with a filled triangle (the head) centered on top of it. The arrow should appear centered (left to right) and at the bottom of the canvas. The shaft should be 10x100 pixels and the arrow head should be in a rectangle of 50x50 pixels 2. The constructor for the Arrow will accept one parameter.. the Canvas on which to draw. It will instantiate the head and the shaft so that they will appear at the bottom center of the Canvas. The constructor will not draw ether component at this time 3. Write a main class, called Controller. Have the main program call the Controller constructor: public class Controller // attributes declared HERE public static void main (String[ args) new Controller) public Controller) t // your problem is to write this code Declare two attributes. One should be an object of class Canvas and the other an object of class Arrow. The constructor is where all the work will be done. Because it is not static, like the main program, it will be able to access the attributes Exercise 2 - Simple Animation (6 points) If you do not complete this exercise during the lab period, you need to complete the work outside of the lab period and bring the completed work to the lab next week. In this exercise, we are going to draw an arrow, pointing up, and animate it... it will move from the bottom of the window to the top that First, we need a class to represent the arrow. The arrow will be a composite class is, it contains two or more classes within it. In our case, besides the canvas on which it is drawn, the arrow will have two visible pieces.. a shaft (a rectangle) and a head (a triangle). To draw the arrow will take two steps, then draw the shaft then draw the head. Similarly for erasing it (erase the head, then the shaft) 1. Write the Arrow class The Arrow class will have the attributes: private Canvas canvas; private Triangle head; private Rectangle shaft; // the canvas on which to dratw // a filled, B&N head // an unfilled, B&W shaft Draw the arrow as an unfilled rectangle (the shaft) with a filled triangle (the head) centered on top of it. The arrow should appear centered (left to right) and at the bottom of the canvas. The shaft should be 10x100 pixels and the arrow head should be in a rectangle of 50x50 pixels 2. The constructor for the Arrow will accept one parameter.. the Canvas on which to draw. It will instantiate the head and the shaft so that they will appear at the bottom center of the Canvas. The constructor will not draw ether component at this time 3. Write a main class, called Controller. Have the main program call the Controller constructor: public class Controller // attributes declared HERE public static void main (String[ args) new Controller) public Controller) t // your problem is to write this code Declare two attributes. One should be an object of class Canvas and the other an object of class Arrow. The constructor is where all the work will be done. Because it is not static, like the main program, it will be able to access the attributesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started