gpt4 book ai didi

java - 文本字段中的键码?

转载 作者:行者123 更新时间:2023-12-01 13:47:02 26 4
gpt4 key购买 nike

我需要为货币值创建一个扩展文本字段的类,当我输入所有值时,我想将其格式化为货币。我正在读这本书,但不明白当我输入值时如何获取键码。

有什么想法或例子吗?

谢谢

最佳答案

您可以 1) 添加一个 Action Listener 来通知您有关关键事件的信息。实现处理程序接口(interface):

// Have the unmodified Enter key cause an event
Action action_ok = new ShortcutAction("Default key", ShortcutAction.KeyCode.ENTER, null);

Action[] actions = new Action[] {action_ok};

public Action[] getActions(Object target, Object sender) {
if (sender == myPanel)
return actions;

return null;
}

/**
* Handle actions received from keyboard. This simply directs
* the actions to the same listener methods that are called
* with ButtonClick events.
*/
public void handleAction(Action action, Object sender, Object target) {
if (action == action_ok) {
okHandler();
}
}

您可以将操作处理程序添加到PanelWindow

// Set this object as the action handler
panel.addActionHandler(this);

所有信息请查看here特别是在 11.5.2 Field Focus Shortcuts 下。

2) 但我建议使用 Converter更多信息here根据 9.2.3。

关于java - 文本字段中的键码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20290692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com