Answer the question
In order to leave comments, you need to log in
Who can help with my paint in Java?
The guys in general wrote paint in the classroom and now I need help. When I draw a square, I want it to be displayed before I draw it, but I have a problem. Who can help?
Here is the whole problem in the video: https://youtu.be/iVjPqU1H_2A .
The code:
case 5:
if (endX != 0 && endY != 0){
g2.setColor(Color.white);
g2.drawRect(startX, startY, endX, endY);
}
g2.setColor(mainColor);
if (xN < e.getX() && yN < e.getY()) {
g2.drawRect(xN, yN, e.getX() - xN, e.getY() - yN);
endX = e.getX()-xN;
endY = e.getY()-yN;
startX = xN;
startY = yN;
}
else if (xN > e.getX() && yN <e.getY()) {
g2.drawRect(e.getX(), yN, xN-e.getX(), e.getY() - yN);
endX = xN - e.getX();
endY = e.getY()-yN;
startX = e.getX();
startY = yN;
}
else if(xN < e.getX() && yN > e.getY()) {
g2.drawRect(xN, e.getY(), e.getX() - xN, yN - e.getY());
endX = e.getX()-xN;
endY = yN - e.getY();
startX = xN;
startY = e.getY();
}
else {
g2.drawRect(e.getX(), e.getY(), xN - e.getX(), yN - e.getY());
endX = xN - e.getX();
endY = yN - e.getY();
startX = e.getX();
startY = e.getY();
}
break;
Answer the question
In order to leave comments, you need to log in
Dumb way:
1) перед началом рисования полностью копируете весь холст без новой фигуры. Т.е. в момент тыка мышкой.
...
2) Вставляете на основной холст чистую копию без фигуры
3) Рисуете прямоугольник
g2.setColor(Color.white);
g2.drawRect(startX, startY, endX, endY);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question