wangmaster

Untitled

Oct 31st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import javax.swing.JPanel;
  3. import javax.swing.JFrame;
  4.  
  5. public class RectSpiral extends JPanel
  6. {
  7. public void paintComponent(Graphics g)
  8. {
  9. int width = getSize().width;
  10. int height = getSize().height;
  11.  
  12. int widthCenter = width / 2;
  13. int heightCenter = height / 2;
  14.  
  15. for (int i = 0; i <= 7 ; i++)
  16. {
  17. g.drawLine(10*i, 10*(i+1), width - 10*(i+1), 10*(i+1));
  18. g.drawLine(widthCenter-5-10*i, heightCenter + 5 + 10*i, widthCenter + 5 + 10*i, heightCenter + 5 + 10*i );
  19. g.drawLine(widthCenter + 5 + 10*i, heightCenter - 4 - 10*(i), widthCenter + 5 + 10*i, heightCenter + 5 + 10*i);
  20. g.drawLine(10 + 10*i, 20 + 10*(i), 10 + 10*i, height - 10*(i+ 1));
  21. }
  22. }
  23.  
  24. public static void main(String[] args)
  25. {
  26. RectSpiral panel = new RectSpiral();
  27.  
  28. JFrame application = new JFrame();
  29.  
  30. application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. application.add(panel);
  32. application.setSize(170, 190);
  33. application.setVisible(true);
  34. }
  35. }
Add Comment
Please, Sign In to add comment