All pastes #10313 Raw Edit

Someone

public java v1 · immutable
#10313 ·published 2005-04-26 00:41 UTC
rendered paste body
/** the problem is that if you place ANY window ON TOP of the the java2d app window that this program *runs - when you ALT-tab inbetween, the colors change *this does NOT just happen with Colors and Java2d, if you use Random to generate a "coordinate position" for instance *the COORDs themselves will change each time you ALT Tab *do not understand what to do here */package ran2dprob;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Rectangle;import java.awt.image.BufferedImage;import java.awt.image.PixelGrabber;import java.awt.geom.GeneralPath;import javax.swing.JFrame;import java.awt.geom.Ellipse2D;import java.awt.GradientPaint;public class Ran2dProb extends JFrame {      public Ran2dProb()   {      super( "Java2d redraw problem when using Random" );        setSize( 200, 150 );        setVisible( true );          }         public void paint( Graphics g )   {            super.paint( g );             Graphics2D graphics2D = ( Graphics2D ) g;               for ( int count = 1; count <= 2; count++ ) {         graphics2D.setColor( new Color(             ( int ) ( Math.random() * 256 ),            ( int ) ( Math.random() * 256 ),            ( int ) ( Math.random() * 256 ) ) );         count++;      }                  graphics2D.fillRect(50,50,90,50);   }                  public static void main( String args[] )   {      Ran2dProb application = new Ran2dProb();      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );                  }}