本文整理汇总了Java中javafx.scene.input.InputEvent.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java InputEvent.getSource方法的具体用法?Java InputEvent.getSource怎么用?Java InputEvent.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.input.InputEvent
的用法示例。
在下文中一共展示了InputEvent.getSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchPressed
import javafx.scene.input.InputEvent; //导入方法依赖的package包/类
public void onTouchPressed(InputEvent event) {
Sketch sketch = new Sketch();
mController.addSketch(sketch, false, false);
double x, y;
if(event instanceof TouchEvent){
x = ((TouchEvent) event).getTouchPoint().getX();
y = ((TouchEvent) event).getTouchPoint().getY();
} else { //event instanceof mouseevent
x = ((MouseEvent)event).getX();
y = ((MouseEvent)event).getY();
}
double xPoint;
double yPoint;
if(event.getSource() instanceof AbstractNodeView){
xPoint = ((AbstractNodeView)event.getSource()).getTranslateX() + x;
yPoint = ((AbstractNodeView)event.getSource()).getTranslateY() + y;
} else {
xPoint = x;
yPoint = y;
}
sketch.setColor(color);
sketch.setStart(xPoint, yPoint);
if(event instanceof TouchEvent) {
currentSketches.put(((TouchEvent)event).getTouchPoint().getId(), sketch);
} else { //event instanceof mouseevent
currentSketch = sketch;
}
}
示例2: onTouchMoved
import javafx.scene.input.InputEvent; //导入方法依赖的package包/类
public void onTouchMoved(InputEvent event) {
Sketch sketch;
double xPoint;
double yPoint;
if(event instanceof TouchEvent){
sketch = currentSketches.get(((TouchEvent)event).getTouchPoint().getId());
if(event.getSource() instanceof AbstractNodeView){
xPoint = ((AbstractNodeView)event.getSource()).getTranslateX() + ((TouchEvent)event).getTouchPoint().getX();
yPoint = ((AbstractNodeView)event.getSource()).getTranslateY() + ((TouchEvent)event).getTouchPoint().getY();
} else {
xPoint = ((TouchEvent)event).getTouchPoint().getX();
yPoint = ((TouchEvent)event).getTouchPoint().getY();
}
} else { //event instanceof mouseevent
sketch = currentSketch;
if(event.getSource() instanceof AbstractNodeView){
xPoint = ((AbstractNodeView)event.getSource()).getTranslateX() + ((MouseEvent)event).getX();
yPoint = ((AbstractNodeView)event.getSource()).getTranslateY() + ((MouseEvent)event).getY();
} else {
xPoint = ((MouseEvent)event).getX();
yPoint = ((MouseEvent)event).getY();
}
}
sketch.addPoint(xPoint, yPoint);
}