Results 1 to 2 of 2

Thread: Drawing Colors in an applet isn't working

Threaded View

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Resolved Drawing Colors in an applet isn't working

    Code:
    import java.awt.*;
    import java.applet.*;
    
    public class Colors extends Applet
    {
    	Color mycolor;
    	//Start with the color red
    	//Red is 255, 0, 0
    	//Yellow is 255,255,0
    	//Green is 0, 255, 0
    	//Cyan is 0, 255, 255
    	//Blue is 0, 0, 255
    	//Magenta is 255, 0, 255
    	
    
    	public void paint(Graphics g)
    	{
    
    	int red=255, green=0, blue=0, x=0;
    
    		//Go from Red to Yellow. Only the 'green' changes (0->255)
    		for(green=0;green<=255; green=green+2)
    		{
    			mycolor = new Color(red,green,blue);
    			g.setColor(mycolor);
    			g.fillRect(x,0,1,50);
    			x++;
    			
    		}	
    		
    		//Go from Yellow to Green. Only the 'red' changes (255->0)
    		for(red=255;red>=0; red=red-2)
    		{
    			mycolor = new Color(red,green,blue);
    			g.setColor(mycolor);
    			g.fillRect(x,0,1,50);
    			x++;
    			
    		}		
    		
    		//Go from Green to Cyan. Only the 'blue' changes (0->255)
    		for(blue=0;blue<=255; blue++)
    		{
    			mycolor = new Color(red,green,blue);
    			g.setColor(mycolor);
    			g.fillRect(x,0,1,50);
    			x++;
    			
    		}		
    
    		
    	}
    }
    In the above code, I think only the first "for loop" is being executed (graphically) because the drawing done by the other loops isn't shown. What could be wrong here?


    <Moderator added green checkmark in the first thread>
    Last edited by NoteMe; Feb 17th, 2005 at 07:12 AM.
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width