我正在尝试为WoW编程一个插件(在lua中).这是一个基于特定单词的聊天过滤器.我无法弄清楚如何使这些单词的数组不区分大小写,以便该单词的任何大写/小写组合与数组匹配.任何想法将不胜感激.谢谢!
local function wordFilter(self,event,msg)
local keyWords = {"word","test","blah","here","code","woot"}
local matchCount = 0;
for _, word in ipairs(keyWords) do
if (string.match(msg, word,)) then
matchCount = matchCount + 1;
end
end
if (matchCount > 1) then
return false;
else
return true;
end
end
Run Code Online (Sandbox Code Playgroud) 我正在进行必须使用AWT完成的Java任务.我想在按钮处于焦点时按下回车键来触发按钮.我想知道如何使用doClick()方法在Swing中执行此操作,但这似乎在AWT中不起作用.到目前为止我正在尝试这个:
button.addActionListener(this); // Passes value from a TextBox to actionPerformed()
button.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
actionPerformed(null);
}
}
});
public void actionPerformed (ActionEvent e) {
try {
if (e.getSource() == button) {
// Stuff I want to happen
} else if (e.getSource() == anotherButton) {
// Other Stuff
} else { //third button
// More stuff
}
} catch (NumberFormatException nfe) {
// Null argument in keyPressed triggers this
// catches empty string exception from …
Run Code Online (Sandbox Code Playgroud)