Solved

Consider an Applet That Implements MouseListener

Question 38

Multiple Choice

Consider an applet that implements MouseListener. Assume that the applet has five instance data, int x1, x2, y1, y2, and boolean inside. The four int values represent the two end-points of a box (x1, y1 is the upper left hand point and x2, y2 is the lower right hand point) . Which of the following properly defines code that will determine whenever the mouse button is clicked if the mouse is currently inside this box or not. If the mouse is inside the box, inside is set to True, otherwise it is set to false.


A) public void mouseMoved(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
B) public void mousePressed(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
C) public void mouseReleased(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
D) public void mouseEntered(MouseEvent me) {
If (me.getX( ) >= x1 && me.getX( ) <= x2 && me.getY( ) >= y1 && me.getY( ) <= y2)
Inside = True;
Else
Inside = false;
}
E) Requires both of the following methods: public void mouseEntered(MouseEvent me)
{
Inside = True;
}
Public void mouseExited(MouseEvent me)
{
Inside = false;
}

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents