当使用 Tuio 进行触摸表应用程序时,我对按钮的监听器感到有点困惑。 我想我需要像 ActionListener() 这样的监听器来用于 Tuio 监听器中的按钮。
你们能给我一些想法吗? 非常感谢。
最佳答案
您必须在 do Implements tuioListener [当您声明您的类时]之后将 TuioListener 添加到 Tuio 客户端
*client = new TuioClient();
client.addTuioListener(this);
client.connect();*
然后,tuio 始终倾听每一次触摸。
然后你必须检查 tuioCursor 方法(添加、更新、删除)你刚刚触摸的组件[通常,当你删除光标时操作就会完成]
假设jButton已经分配了它的Action,代码相对简单。您找到您触摸过的点,触摸该组件,检查它是否是 jButton,将组件强制转换为 jButton,然后它执行其操作。
*public void removeTuioCursor(TuioCursor tc) {
int posX = tc.getScreenX((int) this.getSize().getWidth());
int posY = tc.getScreenY((int) this.getSize().getHeight());
Component comp = this.getComponentAt(posX, posY);
if (comp != null) {
JButton boton = new JButton();
if (comp.getClass().equals(boton.getClass())) {
boton = (JButton) comp;
boton.doClick();
}
}
}*
关于java - 如何使用 tuio 调用按钮的监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805794/