• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about new Color

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all..... Maybe this isn't an awt question after all but anyway

In my JPanel paintComponent i have a lot of rectangles drawn. Like g2.draw( new Rectangle( 1 , 1 , 100 , 100 ) for example. Graphics is cast to a Graphics2D object.

I have a question on new Rectangle and new Color that I use alot. Does this take a lot of memory? I first thought that when paintComponent was done the classes where out of scope and gabage collected but I think my program runs slow. Is it ok to do setColor( new Color( 0 , 0 , 0 ) and new Rectangle or is there a better way of doing this?

// Mathias
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's OK. If your paint methods draws a lot of Rectangles, you might consider some way to avoid creating the objects repeatedly. But if we're talking about less than a hundred or so, I wouldn't give it a second thought. Same with Color objects -- although the color your example shows is black, and I'd simply use the constant Color.BLACK instead.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Yes it's not black color just an example. If I have 1000 rectangels should I put them in a vector or Arraylist or what is the best approch?

// Mathias
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!