mercredi 3 janvier 2018

Call getSource() on a MouseListener?

Is there any way at all to get the source of a MouseEvent for a class that implements MouseListener?

I want to avoid getting it manually by calling

class Foo implements MouseListener {

    Object source = null;

    @Override
    public void mouseClicked(MouseEvent e) {
        source = e.getSource();
    }
}

I would ideally like to be able to do something like

Foo foo = new Foo();

Object source = foo.getSource()

I mean obviously that's not possible, but this has the advantage of not needing to fire an event to actually see what the source of those events is.

So to sum up what I'm trying to do, I need to be able to get the source Object of a MouseListener before any MouseListener events are actually fired. It absolutely needs to be done this way because I need to register another MouseListener to that source before any events are fired within the program. Sorry if there is some obvious terminology I should have used, as I am mostly self-taught I probably missed out on a lot of vocabulary that would make the phrasing of this question much more understandable.

Aucun commentaire:

Enregistrer un commentaire