Hi, i am trying to simulate a paint style program but in the rectangle drawing tool i get some graphic corruption.
The rectangle tool works like this:
with xo, yo the place you press the mouse, and x, y the current place of the mouse when dragging it.
if (x <= xo && y >= yo) {
borrar(x, yo, xo, y);
x = e.getX();
y = e.getY();
graficar(x, yo, xo, y);
} else if (y <= yo && x >= xo) {
clean(xo, y, x, yo);
x = e.getX();
y = e.getY();
graph(xo, y, x, yo);
} else if (x <= xo && y <= yo) {
clean(x, y, xo, yo);
x = e.getX();
y = e.getY();
graph(x, y, xo, yo);
} else if (x >= xo && y >= yo) {
clean(xo, yo, x, y);
x = e.getX();
y = e.getY();
graph(xo, yo, x, y);
}
//the methods graph and clean
public void graph (int x1, int y1, int x2, int y2) {
g.drawRect(x1, y1, Math.abs(x2-x1), Math.abs(y2-y1));
}
public void clean (int x1, int y1, int x2, int y2) {
g.setColor(Color.white);
graficar(x1, y1, x2, y2);
g.setColor(Color.black);
}
as you see its a simple program, if you have an alternative way of doing it i would apreciate if you post it.
Thanks for reading.
The rectangle tool works like this:
with xo, yo the place you press the mouse, and x, y the current place of the mouse when dragging it.
if (x <= xo && y >= yo) {
borrar(x, yo, xo, y);
x = e.getX();
y = e.getY();
graficar(x, yo, xo, y);
} else if (y <= yo && x >= xo) {
clean(xo, y, x, yo);
x = e.getX();
y = e.getY();
graph(xo, y, x, yo);
} else if (x <= xo && y <= yo) {
clean(x, y, xo, yo);
x = e.getX();
y = e.getY();
graph(x, y, xo, yo);
} else if (x >= xo && y >= yo) {
clean(xo, yo, x, y);
x = e.getX();
y = e.getY();
graph(xo, yo, x, y);
}
//the methods graph and clean
public void graph (int x1, int y1, int x2, int y2) {
g.drawRect(x1, y1, Math.abs(x2-x1), Math.abs(y2-y1));
}
public void clean (int x1, int y1, int x2, int y2) {
g.setColor(Color.white);
graficar(x1, y1, x2, y2);
g.setColor(Color.black);
}
as you see its a simple program, if you have an alternative way of doing it i would apreciate if you post it.
Thanks for reading.