I am kind of confusing about the listener for a button when do the touch-table app using Tuio. I think I need the listener like ActionListener() for bu开发者_如何学运维tton in the Tuio listeners.
Could you guys give me some ideas? Thank you very much.
You have to add TuioListener to the Tuio Client after do Implements tuioListener [when you declare your class]
*client = new TuioClient();
client.addTuioListener(this);
client.connect();*
Then, tuio is always listening to every touch.
Then you have to check in tuioCursor methods (add, update, remove) what component you just touched [usually, actions are done when you remove cursor]
Assuming the jButton has its Action already assigned, the code is relatively simple. You find the point you've touched, get the component touched, check if it's a jButton, cast component to jButton and it does its action.
*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();
}
}
}*
精彩评论