Which statement will call the function paint every time the mouse is moved?
Key Terms
9.6.5: Coordinates
var coors;
function start(){
mouseMoveMethod(newCoor);
}
function newCoor(e){
remove(coors);
coors = new Text ("("+ e.getX() + ",...
9.6.6: Target
var x;
var horizontalLine;
var verticalLine;
var y;
function start(){
mouseClickMethod(addBall);
mouseMoveMethod(target);
}
This code from the video draws lines on the canvas when the mouse is pressed down and dragged. But there is one problem. What is wrong with the following code?
1 var line;
2
3 function down(e){
4 var line = new Line(e.getX(), e.getY(), e.getX(), e.getY());
5 add(line);
6 }
7 function drag(e){
8 line.setEndpoint(e.getX(), e.getY());
9
10 }
11
12 function start(){
13
14 mouseDownMethod(down);
15 mouseDragMethod(drag);
16 }
Line 4 declares a new local variable var line. The local variable line in down is different from the global variable line in drag, but we need thes...
How do we fix this problem? The same code is shown again for reference:
1 var line;
2
3 function down(e){
4 var line = new Line(e.getX(), e.getY(), e.getX(), e.getY());
5 add(line);
6 }
7 function drag(e){
8 line.setEndpoint(e.getX(), e.getY());
9
10 }
11
12 function start(){
13
14 mouseDownMethod(down);
15 mouseDragMethod(drag);
16 }
Get rid of the var in Line 4 so that the line in down refers to the same global line in drag rather than a local variable.
Related Flashcard Decks
Study Tips
- Press F to enter focus mode for distraction-free studying
 - Review cards regularly to improve retention
 - Try to recall the answer before flipping the card
 - Share this deck with friends to study together
 
| Term | Definition | 
|---|---|
Which statement will call the function paint every time the mouse is moved?  | mouseMoveMethod(paint);  | 
Suppose we have a callback function paint that is called every time the mouse is moved. Which version of paint will draw a circle at the mouse's location?  | function paint(e){
var circle = new Circle(20);
circle.setPosition(e.getX(), e.getY());
add(circle);
}  | 
9.6.5: Coordinates  | var coors;  | 
9.6.6: Target  | var x;  | 
This code from the video draws lines on the canvas when the mouse is pressed down and dragged. But there is one problem. What is wrong with the following code?  | Line 4 declares a new local variable var line. The local variable line in down is different from the global variable line in drag, but we need these functions to be affecting the same line  | 
How do we fix this problem? The same code is shown again for reference:  | Get rid of the var in Line 4 so that the line in down refers to the same global line in drag rather than a local variable.  | 
9.7.4: Leash  | var BALL_RADIUS = 30;  | 
We've written a function animate that moves a ball across the screen like this:  | function start(){  | 
9.8.4: Basic Snake  | var SNAKE_WIDTH = 40;  | 
We want to write a function changeBall that moves a ball to a random location on the screen and changes its color.  | var x = Randomizer.nextInt(ball.getRadius(),  |