mercredi 20 avril 2016

How to call MouseEvent using Reflection

This is the piece of code I would like to call with Java reflection:

private void cardSlotMouseClicked(MouseEvent mouseEvent) {
  // Some stuff

 }

Here is the code in the class ATM that calls it:

  // cardSlot is a JPanel

  this.cardSlot.addMouseListener(new MouseAdapter(){

        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            ATM.this.cardSlotMouseClicked(mouseEvent);
        }
    });

Here is my code:

    Class a = ATM.class;

    Method m = a.getDeclaredMethod("cardSlotMouseClicked", MouseEvent.class);


    m.setAccessible(true);

    Object o = a.newInstance();

    m.invoke(o, "?"); // What is the argument?

I tried MouseEvent.BUTTON1 but it does not work.





Aucun commentaire:

Enregistrer un commentaire