This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getGraphics on Macintosh  RSS feed

 
Timo von Oertzen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I try to display white noise (pixelwise flickering). Its not fast enough with repaints, so I tried to use getGraphics() and draw some new pixels directly. Following piece of code is called every 10 milliseconds:

graphics = this.getGraphics();
if ((graphics==null) || (true))
{
this.repaint();
} else {
int l1 = myGetWidth();
int l2 = myGetHeight();
int anz = NEWPIXELPROCENT*l1*l2/100;
for (int a=0;a<anz; a++)
{
// r is an Random - object
int c = 100+((int)(r.nextGaussian()*200));
if (c>255) c=255; if (c<0) c=0;
graphics.setColor(new Color(c,c,c));
graphics.fillRect(offsetX+x, offsetY+y, 1,1);
}
}

This works fine on windows, but on Macintosh (Panther Version), it appears getGraphics always return null. I tried some workarounds (like "repaint(x,y,1,1)" on some x and y, or using above code in the paintComponent - method), but results did not look so nice. Has anybody an idea?

Thanks,

Timo
 
Timo von Oertzen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

sorry, the "|| (true)" in the if-condition is of course not in the code (I just had it in for debuging and forgot to delete it before posting).

Best regards,

Timo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!