Question: Task 4. Creating Two Methods to Move the Window Create the following two methods and place a comment above each method. Write a void method

Task 4.

Creating Two Methods to Move the Window Create the following two methods and place a comment above each method. Write a void method (with a comment above it) called snapToTop that moves the window to the top of the screen, but does not change it's horizontal location. If you remember how to do this, do so and move to the next method, if you do not, here are futher instructions. The method should begin: public void snapToTop() { Each method definition in a class goes between the opening curly brace { and the close curly brace } of the class definition. The code should be indented. The code you write inside { } should also be indented and aligned so that each statement inside a compound statement starts on the same column. You will need to call some methods that your class inherits from JFrame (setLocation, getX, getY). You used these methods in the last lab. You can look at that lab for a hint. Hint: Recall that the syntax for a method call is object-reference.methodname(argument list) Your snapToTop method will be run for a specific window (object), and you need to be able to call that window's methods from inside snapToTop. Java provides a reference called this that is used inside a method to get the reference of the object running that method. So, to get the current horizontal location of your window, from inside snapToTop, use this.getX(). Further Hint: you can drop the this. from the method call and just use getX() because if you do not provide a dot operator, Java automatically prefixes this. to the front of the method call. Once you complete the method, save your code and compile it. If it has no errors, test your code: create a new MaxWindow in the Interactions pane, move that window to somewhere other than the top, and call the snapToTop method. If correct, the window should now jump to the top of the screen without changing in size or moving left or right. Place a comment above your method explaining what the method does. You should indent your comment so that it starts in the same column as the method. Create a method snapToLeft that moves the window to the left edge of the screen without changing its vertical location or its size, and put a comment above it. The technique is almost exactly the same as the snapToTop method. Please note, your new method goes inside the { } of maxWindow so it can be part of the class, but it goes outside the { } of snapToTop because the new method is a separate method. Leave a blank line between the closing } of one method and the start of the next method. Special note for Mac's. Apple will not let the the methods you are calling cause the window to cover the Apple Dock (menu of icons). If you have the Dock on the left side of the screen, your window will not move all the way to the left edge. As long as it is as close as possible to the Dock, your method is working correctly. Place a comment above your method explaining what the method does. You should indent your comment so that it starts in the same column as the method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!