I have doubt about MouseEvent consume(). And, what it is used for?
As, I tried an example and I could not figure out what it was doing

Please give your suggestions on this

Thanks


Nick

As, I tried an example and I could not figure out what it was doing

poste your example, maybe that'll show us what you tried and what you didn't understood. this might shed some light on it as well: about MouseEvents

import java.applet.Applet;
import java.awt.event.*;
public class mouseEvent extends Applet implements MouseListener, MouseMotionListener
        // if u use JApplet instead of Applet its same thing..but u need to fix 
{
public void init()
{
addMouseListener(this);  // bcos obj of this class acts as event handler for handling mouselistener event
addMouseMotionListener(this); // bcos obj of this class acts as event handler for handling mousemotionlistener event
}
public void mouseClicked(MouseEvent e)
{
    e.consume();
showStatus("Mouse has been clicked at " + e.getX()+ "," + e.getY()+", ID id" +e.getID()+"consume check"+ e.isConsumed());
}
public void mouseEntered(MouseEvent e)
{
showStatus("Mouse has been Entered at " + e.getX()+ "," + e.getY());// still cannot see this event bcos of overlappping with other events which occur
// For loop:to make sure mouse entered is on status bar for a few sec
for (int i= 0; i<9000000; i++);
} 
public void mouseExited (MouseEvent e)
{
showStatus ("Mouse has been Exited at " + e.getX()+ "," + e.getY());
}
public void mousePressed(MouseEvent e)
{
showStatus ("Mouse pressed at " + e.getX()+ "," + e.getY());
}
public void mouseReleased(MouseEvent e)
{
showStatus("Mouse released at " + e.getX()+ "," + e.getY());
}
public void mouseDragged(MouseEvent e)
{
showStatus("Mouse dragged at " + e.getX()+ "," + e.getY());
}

public void mouseMoved(MouseEvent e)
{
showStatus("Mouse moved at " + e.getX()+ "," + e.getY());
}

}

//Since the applet implements MouseListener and MouseMotionListener it has to provide for the functionality of all their methods. Observe the mouseEntered() method has a small loop to ensure the mouse entered message remains on the status bar for a while. {mospagebreak title=Key Frienldy Codes} Keyboard Events and KeyListener: They are generated on pressing or releasing a key. The KeyEvent class contains constants to represent the keys pressed or typed. The event listener corresponding to these types of event is the KeyListener.

//The following example puts forth key event handling. The applet contains a label and a text field. The recently typed in character in the text field is displayed in the status bar. Example 4.

this is what I found in the API's:
consume

public void consume()

Consumes this event so that it will not be processed in the default manner by the source which originated it.

Overrides:
consume in class AWTEvent


honnestly, I've never used it, so I can't explain the specific details.

now, since it is an example you wrote, you had something in mind it was supposed to do. so, what were you trying to accomplish?

I was trying to see if using consume() will block the processing of event

but the event was handled in default manner

I was trying to see if using consume() will block the processing of event

but the event was handled in default manner

as I quoted out of the api's, consume() makes sure it's not processed in default manner. so, did you call consume(), and how did you do that, if it still processed in default manner?

i was not able to fix it using this technique. As mentioned in the above code, I did call consume() here....


public void mouseClicked(MouseEvent e){ e.consume();showStatus("Mouse has been clicked at " + e.getX()+ "," + e.getY()+", ID id" +e.getID()+"consume check"+ e.isConsumed());}

but it did not wrk for me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.