有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用tuio调用按钮的侦听器?

我有点搞不懂,当你用Tuio做触摸屏应用时,你的听者需要一个按钮。 我想我需要像ActionListener()这样的监听器,用于Tuio监听器中的按钮

你们能给我一些建议吗? 非常感谢


共 (1) 个答案

  1. # 1 楼答案

    在do实现TuioListener之后,您必须将TuioListener添加到Tuio客户端[当您声明类时]

    *client = new TuioClient();
    client.addTuioListener(this);
    client.connect();*
    

    然后,tuio总是在倾听每一次触摸

    然后,您必须签入tuioCursor方法(添加、更新、删除)您刚刚接触的组件[通常,在删除光标时会执行操作]

    假设jButton已经分配了它的操作,那么代码相对简单。找到你接触的点,触摸组件,检查它是否是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();
         }
      }
    }*