Hello, I've got this problem with an intro to Java class. To lay some background down, the professor teaches the 'theory' behind java, and nothing of actual code, so my knowledge is very limited here.
The reason I'm here is I can't discern for the life of me how to clear a java Canvas. I've created shapes on it (rectangles, lines etc). But the goal I seek here is to create a clear button (which will clear the canvas, and let the use create more of the same shapes with the same color) and a reset button(which does the same as clear, but resets to normal). With the reset button, I got everything to reset, but it does not erase.
ex code of that
case OVAL :
diameter = Math.max(width, height);
if(filledColor == null)
g.drawOval(x, y, width, height);
else
g.fillOval(x, y, width, height);
break;
I have no real idea how to erase it. My professor vaguely hinted at clearRect, but I'm at a loss as to how to implement this. Here are the things I've tried from sources all over the internet:
case CLEAR :
//repaint();
//g.clearRect(x, y, width, height);
g.setColor(getBackground());
g.clearRect(0, 0, width, height);
break;
When I do use it, My current shape selection disappears. And when used with reset, the shape stays, but reverts to the standard shape when the program starts. Is there another way, that would just erase the canvas?
Thanks in advance.