title: Drawing Lines in Java with a loop
body: <p>I need help drawing lines in Java. I have written the code for one corner with 15 lines. But I am having trouble figuring out how to draw these 15 lines again in each of the 4 corners at the same time. Can anyone show me how to mirror my current code in each of the 4 corners?</p>
  
  <pre><code>import javax.swing.JFrame;
  
  public class DrawOneSetOfLines extends JPanel
  {
  public static void main(String args[])
  {
      DrawOneSetOfLines panel = new DrawOneSetOfLines();
  
     JFrame application = new JFrame();
  
  
      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      application.add(panel); 
      application.setSize(250, 250); 
      application.setVisible(true); 
  } 
  
  public void paintComponent(Graphics g)
  {
  
      super.paintComponent(g);
  
      int linesToDraw = 15;
      int width = getWidth(); 
      int height = getHeight(); 
      int number, y, x, dy, dx;
        x = 0;
        y = height;
        number = 15;
        dx = width / number;
        dy = height / number;
        for( int i = 1; i &lt; number; i++ )
        {
          x += dx;
          y -= dy;
          g.drawLine( 0, 0, y, x );
  
  
  } 
  } 
  }
  </code></pre>