• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem changing colours

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic