다른 색상으로 캔버스에 점을 그리려고합니다. 기본적으로 파란색의 현재 점, 녹색 및 점의 현재 점보다 먼저 그려지는 점은 빨간색의 현재 점 다음에 그립니다. 코드 이해를 높이려면캔버스의 위치 ((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, 나중에 사용해보고 u 리뷰를 제공 해드립니다. –