キャンバス上に異なる色で点を描こうとしています。基本的に、現在のポイントは青で、ポイントは緑とポイントの現在のポイントの前に描画され、ポイントは赤で現在のポイントの後に描画されます。コードを参照してくださいキャンバス上での位置((x、y)座標)に応じて異なる色のSWTポイントを描く
private void setElemColor(GC g, int pos) {
int currentPoint = messtisch.getPointPos(); //current point, number
if (pos > currentPoint) {
g.setForeground(cRed);
} else if (pos == currentPoint) {
g.setForeground(cBlue);
} else if (pos < currentPoint) {
g.setForeground(cGreen);
}
}
理解を高めるために。これは完璧に動作します。しかし、私はIntの代わりにPointを使用して、同じことを行い、論理的な権利が得られないようにしようとしています。
のとおりprivate void setPointColor(GC g, Point cpoint) {
if (cpoint.equals(currentPoint)) { // the current point itself
g.setForeground(cBlue);
} else if (!cpoint.equals(currentPoint)) {
if (cpoint.x > currentPoint.x || cpoint.y > currentPoint.y) {
g.setForeground(cRed);
} else {
g.setForeground(cGreen);
}
}
}
のように私を助けてください。
ありがとうございます@BoffinbrainN、後で試してみてください。 –