0
我試圖讓我的代碼使用Leap Motion在0和255之間的數字向上滾動(所以打印:1,然後2,然後3在cw圓圈和3,2 ,1個圈)。Java:Leap Motion返回值void
手勢的操作駐留在void onFrame()方法中。
我需要增加一個數字,每次檢測到圓圈手勢並輸出每一個數字。就目前而言,我的代碼在後臺遞增,只有當我輸入數字時纔算數(所以我的數字在第二個提示中顯示)。這很糟糕,因爲用戶實際上看不到他們提交閾值提示的數字。
請幫助,我對此很新,它會減慢我的項目速度!
我已經提供了精簡類,以突出問題所在。
Listener類:
public class ImageJListener extends Listener {
public Robot robot;
public int promptValue;
// potentially look into atomic objects and non atomic objects in case this has a threading issue
public ImageJListener() {
this.promptValue = 0;
}
public int getPromptValue() {
return this.promptValue;
}
...
public int onFrame(Controller controller) {
com.leapmotion.leap.Frame frame = controller.frame();
for (Gesture gesture : frame.gestures()) {
if (gesture.type() == Type.TYPE_CIRCLE) {
CircleGesture circle = new CircleGesture(gesture);
if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI/4) {
promptValue++;
return promptValue;
} else {
promptValue--;
return promptValue;
}
} else if (gesture.type() == Type.TYPE_KEY_TAP) {
KeyTapGesture Tap;
Tap = new KeyTapGesture(gesture);
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException awt) {
}
}
}
}
}
插件類(即調用promptValue變量來填充提示:
IJ.setRawThreshold(imp, IJ.getNumber("prompt", (listener.getPromptValue())), IJ.getNumber("prompt", (listener.getPromptValue())), null);
提前許多感謝,
瑞安
我正在考慮使用Observable類將更新抽出 - 你認爲這會削減嗎? –
調用單個函數看起來有點矯枉過正,但是如果您預計需要發送更多的數據,那麼只需要這個整數,那麼也許這是值得的。不過,我並不是一個真正的Java人,所以我給你Java風格的指導是愚蠢的。 –