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?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++; } } }
<Moderator added green checkmark in the first thread>


Reply With Quote