如何使用tuio来调用按钮的监听器?

时间:2011-07-24 08:39:15

标签: java multi-touch

当使用Tuio进行触摸桌应用时,我对按钮的监听器感到困惑。 我想我需要像Tuio监听器中的按钮一样的ActionListener()监听器。

你们可以给我一些想法吗? 非常感谢你。

1 个答案:

答案 0 :(得分:2)

在执行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();
     }
  }
}*