I started by removing some of the code with the intent of replacing it with different code utilizing a different approach:
I was surprised to see that the app worked (just as it did before) after the code was removed (Vector, Enumeration, Point; with very few other changes). Now, I'm wondering why some of this original code was necessary at all. Can anyone explain? Thanks!
Now, I know we have an FAQ telling people off for simply saying, “It doesn't work,” but never thought we would have somebody posting, “It does work.”
And I know there is beginners' code where you can delete 50% of it without noticing any difference, but this looks different.
What exactly happened? Did you recompile the code? Did you suffer any compile‑time errors? Are you using an IDE?
Maybe you still have the old .class files around.
posted 6 years ago
Well, I found the 1st set of code, CanvasX (my name) just poking around. I created another Class, CanvasX2, in the same Eclipse Java Project. I edited CanvasX2 and re-ran it. I believe Eclipse compiles as you write the code. I believe that any problems would be pointed out when the Class is run. I did Clean the Project just to be sure. No Eclipse error flags. No Errors in Console when the Classes are run.
posted 6 years ago
Grrr! In reviewing this post I realized that the code that I had changed actually commented out this line:
...as I have since learned this will prevent the CanvasX2 JPanel from repainting it's background. Multiple squares however, will still be painted. Once the background IS repainted, e.g. resize the window, only one square remains. I can kind of get the same effect by just painting 5 squares when paintComponent is overridden:
If I click again super.paintComponent repaints the JPanel's background and provides 5 new squares.
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad: