マウスボタンをクリックしても読み取られない
温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
(提案に沿って編集)
プログラミングプロジェクトのシードソリューションを実装しようとしています。
- マウスクリックを処理するプライベートイベントハンドラー。左クリックでポイントを追加し、右クリックでポイントを削除し、その後の最大ポイントセットを再計算します。
私の到来 (またはエラーを絞り込む場所):
public class PointPane extends Pane {
private final ArrayList<Point> points;
public PointPane(ArrayList<Point> points) {
this.points = points;
drawPoints();
this.setOnMouseClicked(this::handleMouseClick);
}
// this is the section with the issue
private void handleMouseClick(MouseEvent event) {
// after entry it should be checking for the left or right mouse button, but
// it does not enter either the if or the else if and goes directly to
// drawPoints();
if (event.isPrimaryButtonDown()) { // Left click
points.add(new Point(event.getX(), event.getY()));
} else if (event.isSecondaryButtonDown()) { // Right click
Point pointToRemove = null;
for (Point point : points) {
if (Math.abs(point.getX() - event.getX())
< 5 && Math.abs(point.getY() - event.getY()) < 5) {
pointToRemove = point;
break;
}
}
if (pointToRemove != null) {
points.remove(pointToRemove);
}
}
drawPoints();
}
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2524
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
-
浏览(166) 评论(0)