Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Create a program that starts by displaying a diamond with the corners at the middle of each edge of the screen: You can set

image text in transcribed
image text in transcribed
java
Create a program that starts by displaying a diamond with the corners at the middle of each edge of the screen: You can set this up in your class's begin() method. Use constants -- variables that are both static and final -- to give the initial positions of the lines. Now create a program that will cause this diamond to "expand" each time the user clicks on the window. You do not need to actually have the diamond expand -- you can simulated this effect by moving the lines defining the diamond such that each line moves a little bit closer to the corner each time the window is clicked, making it seem as if the diamond is becoming too large to display on the window. Write a program that emulates a broom that can sweep an object around the screen. The broom will be represented by a small ball with diameter 10 that appears when the mouse is pressed and disappears when the mouse is released. While the mouse is depressed, the broom (ie, ball) is dragged along by the mouse (the upperleft corner of the broom should always be at the mouse location. In the image below, the broom is partly hidden underneath the cursor arrow. The "dirt" you are sweeping will be represented by a filled square (30 pixels to a side) shown on the screen. If the broom bumps into the square while being dragged (as shown in the image above), then the square will move the same distance (and in the same direction) as the broom, as it would if you had a real broom. Notice that we are asking you to have the broom push the square, rather than have the mouse drag the square. Thus if the mouse is depressed when it is not over the square, but then is dragged toward the square, the square should be pushed ahead of the mouse only when the circle that represents the broom is moved into a position where it would overlap with the square. Once this happens, the square will be pushed in the same direction and for the same distance as the mouse was just moved. As a result, when the mouse (and the circle) stop moving the mouse and the circle will still not be on top of the square. When the mouse leaves the window, you should reset the box back to its original position. The reference available here will almost certainly be useful in completing this project. The onMouseDrag method will (almost certainly) be useful in this project. There are other methods that can simplify this project: I leave it to you to find them. As you write your program, you should not worry about the possibility that the mouse is pointing at the square when it is first depressed. If you do this, we expect that the code you write will result in behavior that looks more like dragging than pushing if someone does try depressing the mouse while pointing at the square. That is, in this case, the circular broom will appear in a position overlapping the square and the two shapes will move around the screen together as you drag the mouse. One warning: If you move the broom diagonally while pushing the square, the square will have a tendency to slide off of the broom. This is because movements parallel to the side of the square will not affect the square (and the computer is so fast that some of your diagonal moves will end up parallel to the square). This is a "feature" not a "bug" (this is what happens with real brooms), so don't worry about it as long as the square generally is moved along with the broom

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

Explain how a go/not-go ring gage works for check a shaft.

Answered: 1 week ago