0
這是一段代碼來調用的MouseEvent我想與Java反射調用:如何使用反射
private void cardSlotMouseClicked(MouseEvent mouseEvent) {
// Some stuff
}
這裏是班上ATM調用它的代碼:
// cardSlot is a JPanel
this.cardSlot.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent mouseEvent) {
ATM.this.cardSlotMouseClicked(mouseEvent);
}
});
這是我的代碼:
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?
我試過MouseEvent.BUTTON1,但它不起作用。
有沒有辦法告訴JPanel執行操作,因爲MouseAdapter是由JPanel調用的? – user6212007
無論你將添加此鼠標適配器,只要在該組件上單擊鼠標,它將被調用 – Sanjeev
我正在嘗試模擬黑客。鏈接到ATM:https://codepad.co/snippet/yjATRN3S,卡片:https://codepad.co/snippet/Z0zZfNhW – user6212007