![]() ![]() e.g. Myself I'd do things differently by using an array or ArrayList of Color, and then incrementing the counter and selecting the correct item out of the array. A solution is to set all booleans to false within your key pressed method, and then only set the correct one to true. ![]() You're setting all colors true and none false, so you end up drawing the same line over and over, and eventually, the only color you see is black. I will write here a part of my code, maybe is not the best way to do it, but I'm new in AWT. Until here everything works fine, but when counter resets and increments again, color is still the same, black, for any value of counter. I will write here exactly what it happens: counter = 1 => color red (Before, you were not only trying to paint the same line in each iteration of the loop, but also a line that did not exist yet, thus the. In paint() method I check those boolean values above, and if they are true, I change color.įirst time, until counter is reseting, I can change colors fine, but after counter reset, my colors will not change. to this: g.drawLine (points i.x, points i.y, pointends i.x, pointends i.y) This will get rid of the NullPointerException and the lines will be drawn correctly once you release the mouse button. ![]() Because I have 5 variables, when counter reach value 6, I reset counter and it starts again from 1, with red color. I have a variable int counter = 0 and I use it to increment in function keyPressed(KeyEvent e). I have 5 boolean variables boolean redColor = false I am trying to draw a line, and change color every time I press 'c' for example. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |