• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem changing colours

 
Nick Austin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I currently have a small problem with drawing different colours to my JPanel. I currently have buttons that changes the value of an int (colourStatus) when pressed. it also calls a method to change the colour, based upon the status selected.



now that i hve the colour selected, i apply before drawing my shapes



the problem is the colour changes just fine, but all other lines draw on the screen also change to the new colour, is there a way i can just apply changes to any new lines that are drawn

Thanks Nick
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about storing the color in your Line instances, and use that color? That way each Line instance knows its own color.
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the lines are going to be redrawn repeatedly. If you want "change colour" to mean "Any new lines should be this new colour but the old lines should still be drawn with whichever colour they were originally drawn with", then you'll need a data structure which keeps track of what colour a line should be redrawn with, when it's redrawn.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Custom Painting Approaches has an example that does this with Rectangles.
 
Nick Austin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers guys, all the help was appriciated, have managed to implement the change colour by passing the colour each time the object is created.

Thanks again Nick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!