Javamhxy event association mechanism

Source: Internet
Author: User

At the beginning, the program event was triggered by firepropertychanged. Later, I wanted to change it to a script to dynamically configure the game framework. Obviously, I cannot specify which key/button corresponds to any event in the code. I have only been familiar with Eclipse plug-ins and some knowledge about Java keyboard binding, so I followed the feeling and made a dynamic loading framework based on my own ideas.

Buttons -- trigger --> action:The Java buttons are used to bind inputmap & actionmap.

Button -- trigger --> action:This association is done manually. Using actionid to associate a specific action is jbutton. setaction (). Of course, the component is created in the interpreter scriptloader.

Share actions:Create a Global static actionmap. All events are added to the actionmap when they are loaded. put (ID, action), the following control can obtain the corresponding action according to the ID, this must be in the order of loading, otherwise the processing Code cannot be shared.

Describes the XML format of hotkey:

<Hotkey keycode = "W" Mask = "Alt"Actionid = "com. jmhxy. dialogs. Character status"/>

Describe the XML format of the button:

<ButtonActionid = "com. jmhxy. dialogs. Character status"X = "106" Y = "3" was = "/resources/character welement/profile picture/feiyan female. Was"/>

XML format of the description action:

<ActionId = "com. jmhxy. dialogs. Character status"Class = "com. jmhxy. Actions. hotkeyactions"/>

In this way, events and targets are associated by ID. The Interpreter analyzes XML elements and attributes, loads processing classes through class reflection, and obtains instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.