how can i draw more rectangle?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dl3kla
    New Member
    • May 2010
    • 8

    how can i draw more rectangle?

    hello

    how can i draw more rectangle in JApplet 10 time with different size

    this my program

    import javax.swing.JAp plet;
    import java.awt.*;

    public class draw extends JApplet {

    public void init() {

    repaint();
    }
    public void paint(Graphics g) {
    int a=0;
    int X=0;
    int Y=0;
    g.drawRect(X,Y, 30, 10);
    for(a=0;a<=10;a ++)

    g.drawRect(X+10 ,Y+10,30,15);
    a=a+1;
    {

    }
    }
    }
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Originally posted by dl3kla
    hello

    how can i draw more rectangle in JApplet 10 time with different size

    this my program

    import javax.swing.JAp plet;
    import java.awt.*;

    public class draw extends JApplet {

    public void init() {

    repaint();
    }
    public void paint(Graphics g) {
    int a=0;
    int X=0;
    int Y=0;
    g.drawRect(X,Y, 30, 10);
    for(a=0;a<=10;a ++)

    g.drawRect(X+10 ,Y+10,30,15);
    a=a+1;
    {

    }
    }
    }
    for(a=0;a<=10;a ++)

    g.drawRect(X+10 ,Y+10,30,15);
    a=a+1;
    that loop of yours is totally incorrect..
    you shouldn't increment the counter of a for loop when you're already incrementing it in the for loop definition.

    And

    It seems that you're drawing the rectangle in the same location everytime..

    you must change the location of the image by some counter
    a more better for loop is listed below
    Code:
    int x=0;
    int y=0;
    for(a=0;a<=20;a++)
    {
    g.drawRect(x,y,30,15);
    x+=0;
    y+=10;
    }

    hope it works

    Comment

    • dl3kla
      New Member
      • May 2010
      • 8

      #3
      thank you very much

      Comment

      Working...