All pastes #10316 Raw Edit

Mine!

public java v1 · immutable
#10316 ·published 2005-04-26 01:26 UTC
rendered paste body
As you advised Blackwell, tried to create the "random colors" outside of method "paint()" however, the same issue still exists as defined below thank you for helping!the problem is that if you place ANY window ON TOP of the the java2d app window that this programruns - when you ALT-tab inbetween, the colors changethis does NOT just happen with Colors and Java2d, if you use Random to generate a "coordinate position" for instancethe COORDs themselves will change each time you ALT Tabdo 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 {       private int colorNum;   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;       /** per Blackwell, take this out of paint() and make it into a method                for ( int count = 1; count <= 2; count++ ) {         graphics2D.setColor( new Color(             ( int ) ( Math.random() * 256 ),            ( int ) ( Math.random() * 256 ),            ( int ) ( Math.random() * 256 ) ) );         count++;      }      */           ////////////////////////////////////// new version                 graphics2D.setColor( new Color( colorChanger(), colorChanger(), colorChanger() ) );         graphics2D.fillRect(50,50,90,50);   }            /////////////////////////////////////////////////////below am creating the Random Colors so they aren't created in 'paint()" method   /////////////////////////////////////////////////////above   public int colorChanger() {              int aber =  ( int ) ( Math.random() * 256 );                 return colorNum = aber;         }            public static void main( String args[] )   {      Ran2dProb application = new Ran2dProb();      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );                  }}