lundi 27 avril 2020

Generic (JComponent) event handling in Java?

I'm implementing a scripting language on top of the Java VM. Using reflection, I'm able to dynamically create Java helper objects, access their fields and invoke their methods. However, I have now hard-coded handling for specific event types. E.g.: JScrollBar addAdjustmentListener() using the Adjustable interface, JFrame windowClosing() using the WindowAdapter interface, JButton addActionListener using the ActionListener interface. On the event receiving end in the scripting language, an anonymous function is called with the event data, with 0, 1 or 2 parameters of arbitrary types. My question is: Is there a (reflective) way in Java to handle arbitrary events? Generically handling all JComponent subclass events would be a good start too.





Aucun commentaire:

Enregistrer un commentaire