I am using swing to nest squares with in squares (256 times) and that part is working fine, but what i want to do is change the color of each line so that the red green and blue components each increment by 1 each time the next line is drawn. I really never used jpanel or jframe much less swing. any help I coulg get would be appreciated.
Thanks in advance.
here is the code i've got thus far
Thanks in advance.
here is the code i've got thus far
Code:
package nestedsquare;
import javax.swing.JFrame;
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame application = new JFrame();
DrawSquares panel = new DrawSquares();
String myTitle = " NestedSquare ";
application.setTitle(myTitle);
application.add( panel ); // add the panel to the frame
application.setSize( 263, 290 ); // set the desired size
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setVisible(true);
}
}
Code:
package nestedsquare;
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawSquares extends JPanel
{
public DrawSquares()
{
}
// draws a cascade of shapes starting from the top left corner
public void paintComponent( Graphics g )
{
super.paintComponent( g );
for ( int i = 0; i < 256; i++ )
{
g.drawRect( 1 + i++, 1 + i++,
256 - i*2 , 256 - i*2 );
}
}
} // end method
Comment