Advertisement
Guest User

tomataolindao

a guest
Mar 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package aula3;
  7.  
  8. import javax.swing.JFrame;
  9. import java.awt.Color;
  10. import java.awt.Graphics;
  11. import java.awt.Polygon;
  12. import javax.swing.JOptionPane;
  13.  
  14. /**
  15. *
  16. * @author aluno
  17. */
  18. public class aula3 extends JFrame{
  19.  
  20. aula3(){
  21. setSize(840, 480);
  22. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23. setVisible(true);
  24. }
  25.  
  26. @Override
  27. public void paint(Graphics g) {
  28.  
  29.  
  30. int r = 150;
  31. int cx = 200;
  32. int cy = 200;
  33.  
  34. //entrada dos lados do poligono
  35. //int l = 10;
  36.  
  37. String a = JOptionPane.showInputDialog("Total de lados: ");
  38. int l = Integer.parseInt(a);
  39.  
  40. Polygon p = new Polygon();
  41.  
  42. for (int i=0; i < l; i++){
  43. p.addPoint(
  44. (int) (cx + (r * Math.cos(i * 2 * Math.PI/l))),
  45. (int) (cy + (r * Math.sin(i * 2 * Math.PI/l)))
  46. );
  47. }
  48.  
  49. g.setColor(Color.MAGENTA);
  50. g.drawPolygon(p);
  51.  
  52. }
  53.  
  54. public static void main(String[] args) {
  55. // TODO code application logic here
  56. new aula3();
  57.  
  58. }
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement