Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Lab Examples

Q1.
Spoiler (Click to View)
Q2.
Spoiler (Click to View)
Code
if (check = true){
            //HELP
            
        }

Oh boy. What is this for?
It is where you put the code to enlarge the circle. If the point is in the circle then it will execute the code below check=true
(Dec 12, 2016 12:26 PM)makawan Wrote:  It is where you put the code to enlarge the circle. If the point is in the circle then it will execute the code below check=true

= is for assignment, use == for comparison.
But it's best to only leave the boolean check in your if statement.
if (check) would already execute if check were true, because you would have if (true) and viceversa it would not if check is false.
Oh i c. Thanks for the help. Any ideas to resize the selected circle?
Quote: This program should initially show a dot on the canvas, and enlarge the dot when a mouse grabs and drags it.

Okay, not so hard I see. Lets tackle it thinking in logical steps. I see The code to draw the dot is already given to you (or you have already completed it). Nice.

You have a method setting a boolean to either true or false. Since the
Code
onMousePress(Location point)
method is only called when you press the mouse, this check will only set
Code
check
to true when you press the mouse and it's inside the dot. Nice.

Lets look at this next part without any knowledge of the onMouseDrag (since I don't know which library this mouse controller is coming from specifically).

First step, find what Location is being passed in through that argument "point". You can either print out some variables from point (probably and x and y) or just print out the object itself:
Code
System.out.println(point.toString())
or
Code
System.out.println(point.getX() + " " + point.getY())
Okay, so I'm assuming this point passed in is the current position of your mouse when you have the button pressed down.

First off, the "=" operator is an assignment while "==" is conditional, so change:
Code
if (check = true) {}
to
Code
if (check) {}
or
Code
if (check == true) {}

To change the size of the dot, we want to change its radius. Following a simple rule, we can say as the mouse is being dragged away from the center, we should increase the radius.

To do this, have global (class) variables storing the initial X and Y (center) location of the original dot. As the user drags their mouse, find the X and Y position of the mouse (through the point argument) and calculate the distance (distance formula) and set that distance to the radius of the circle.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by StarZJan 1, 2021 01:32 PM 10 1,030 Jan 1, 2021 01:32 PM
Last Post: mose3c
[Shell] by gurlhackerclubMar 6, 2020 06:50 AM 0 151 Mar 6, 2020 06:50 AM
Last Post: gurlhackerclub
[C] by jimcola99Jan 14, 2020 03:29 PM 1 182 Jan 14, 2020 03:29 PM
Last Post: akali