【问题标题】:Processing - Managing ArrayLists处理 - 管理 ArrayLists
【发布时间】:2017-07-11 04:19:25
【问题描述】:

我正在尝试管理这个ArrayList。基本上我有一个ArrayListPVector 对象-在我的代码中有两对(x,y) 变量进入数组。我想知道如何分别管理这两对。我需要知道哪一个是(x1,y1),哪一个是(x2,y2),并可能命名它们。我该怎么做?

Blob(float x, float y) {
  minx = x;
  miny = y;
  maxx = x;
  maxy = y;
  points = new ArrayList<PVector>();
  points.add(new PVector(x, y));
}

【问题讨论】:

标签: processing


【解决方案1】:

根据您的问题,我不完全确定您想要实现什么,但如果您想从您的 blob 函数创建 2 个 PVector 对象并将它们添加到您的 ArrayList,然后再添加 2 个函数的参数。例如:

void blob(float x1, float y1, float x2, float y2) {
  minx = x1;
  miny = y1;
  maxx = x2;
  maxy = y2;
  points = new ArrayList<PVector>();
  points.add(new PVector(minx, miny));
  points.add(new PVector(maxx, maxy));
}

然后您可以使用ArrayList索引 来识别两个PVector 对象,并为它们命名,您可以将它们分配给变量。例如:

PVector firstPoint = points.get(0);
PVector secondPoint = points.get(1);

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 2014-10-04
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多