Question: You are required to display a square and move it through arrow keys. The user should not be allowed to move the square outside the

You are required to display a square and move it through arrow keys. The user should not be allowed to move the square outside the displayed area. Square should be rendered and moved using Graphics class, fillRect and repaint methods. Each key press should move the square a fixed amount of pixels, so you should use absolute positioning. Movement should be in the direction of the key pressed, namely up arrow key should move the square upwards, right arrow key should move square to the right and so on. You can write your code on top of the provided MoveBoxWithAbsolutePositioning.java . You can find the Graphics example in RectPanel.java class. Expected output can be seen in the Application Walkthrough section. You are required to display a square and move it through arrow keys. The user should not be allowed to move the square outside the displayed area. Square should be rendered and moved using Graphics class, fillRect and repaint methods. Each key press should move the square a fixed amount of pixels, so you should use absolute positioning. Movement should be in the direction of the key pressed, namely up arrow key should move the square upwards, right arrow key should move square to the right and so on. You can write your code on top of the provided MoveBoxWithAbsolutePositioning.java . You can find the Graphics example in RectPanel.java class. Expected output can be seen in the Application Walkthrough
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
