Question: Program in Java The assignment is to utilize the above mentioned packages to track the mouse position. There should be a turtle created in a
Program in Java
The assignment is to utilize the above mentioned packages to track the mouse position. There should be a turtle created in a new world/window. This is created by using the import edu.support.EndWorld; This creates a new world: EndWorld w= new EndWorld(); To create a turtle use: import edu.gatech.mediacomp.Turtle; This places a turtle in that world/window: Turtle t = new Turtle(w);
The assignment is to move the turtle around with the mouse. When the mouse enters the new world/window, the turtle should turn towards the mouse and start moving forward until it reaches the mouse's position. If the mouse moves, the turtle should adjust and continue moving towards the new position. If the mouse exits the world, the turtle should stop moving. We must use a timer to control the speed of the turtle!
Be sure to add the mouse listeners to the EndWorld directly NOT the frame!
There are 2 different interfaces you will need for handling mouse events.
As noted above you need to have the turtle start/stop moving based on:
1) Whether it is already at the position of the mouse.
2) If the mouse pointer is in the drawing area. This latter one can be handled by using the Point object that the TurtleMouseFollower has.
Below is a link where I have uploaded all programs needed to support this assignment. It only requires 2 programs that are required to be created that needs to be uploaded (Main.java and TurtleMouseFollower.java) Please copy and paste the text code as an answer. Also below is a map of how it should be called and implemented.
http://www.mediafire.com/file/08303b2zzef54ih/TurtleMouseFollowStarter.zip
cop2513 turtlemousefollow: ain +main (String args): void edu support EndWorld edu.gatech.media comp: Turtle javax.swing: Timer java.awt: Point cop2513.turtlemousefollow::TurtleMouseFollower C-FORWARD PIXELS: int +TurtleMouseFollower(): ctor cop2513 turtlemousefollow: ain +main (String args): void edu support EndWorld edu.gatech.media comp: Turtle javax.swing: Timer java.awt: Point cop2513.turtlemousefollow::TurtleMouseFollower C-FORWARD PIXELS: int +TurtleMouseFollower(): ctor
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
