I am currently working an Assignment that involves creating a square shaped spiral using loops. I thought I'd figure it out but I found out that the right side of the square spiral is not drawing a line.. Any ideas on how to fix this.. Thanks a lot you guys.
P.S. I uploaded a picture of my output, if you guys could please look at it to know what I'm talking about or you could instead copy and run the code on your computers ... Thanks for your help..
import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JFrame; public class JAssign4B extends JPanel { public void paintComponent(Graphics g) { int width = getSize().width; int height = getSize().height; int widthCenter = width / 2; int heightCenter = height / 2; for(int i = 0; i < 4; i++) { g.drawLine(widthCenter + (20 * i), heightCenter + (20 * i), widthCenter + (20 * i), heightCenter + 20 + (20 * i)); g.drawLine(widthCenter + (20 * i), heightCenter + 20 + (20 * i), widthCenter - 20 - (20 * i), heightCenter + 20 + (20 * i)); //increase width and height here..... g.drawLine(widthCenter - 20 - (20 * i), heightCenter + 20 + (20 * i), widthCenter - 20 - (20 * i), heightCenter - 20 - (20 * i)); g.drawLine(widthCenter - 20 - (20 * i), heightCenter - 20 - (20 * i), widthCenter + 20 + (20 * i), heightCenter - 20 - (20 * i)); } } public static void main(String[] args) { JAssign4B panel = new JAssign4B(); JFrame application = new JFrame(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); application.add( panel ); application.setSize( 300, 300 ); application.setVisible( true ); } }