Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import javax.swing.JPanel;
- import javax.swing.JFrame;
- public class RectSpiral 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 <= 7 ; i++)
- {
- g.drawLine(10*i, 10*(i+1), width - 10*(i+1), 10*(i+1));
- g.drawLine(widthCenter-5-10*i, heightCenter + 5 + 10*i, widthCenter + 5 + 10*i, heightCenter + 5 + 10*i );
- g.drawLine(widthCenter + 5 + 10*i, heightCenter - 4 - 10*(i), widthCenter + 5 + 10*i, heightCenter + 5 + 10*i);
- g.drawLine(10 + 10*i, 20 + 10*(i), 10 + 10*i, height - 10*(i+ 1));
- }
- }
- public static void main(String[] args)
- {
- RectSpiral panel = new RectSpiral();
- JFrame application = new JFrame();
- application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- application.add(panel);
- application.setSize(170, 190);
- application.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment