Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package aula3;
- import javax.swing.JFrame;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Polygon;
- import javax.swing.JOptionPane;
- /**
- *
- * @author aluno
- */
- public class aula3 extends JFrame{
- aula3(){
- setSize(840, 480);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- @Override
- public void paint(Graphics g) {
- int r = 150;
- int cx = 200;
- int cy = 200;
- //entrada dos lados do poligono
- //int l = 10;
- String a = JOptionPane.showInputDialog("Total de lados: ");
- int l = Integer.parseInt(a);
- Polygon p = new Polygon();
- for (int i=0; i < l; i++){
- p.addPoint(
- (int) (cx + (r * Math.cos(i * 2 * Math.PI/l))),
- (int) (cy + (r * Math.sin(i * 2 * Math.PI/l)))
- );
- }
- g.setColor(Color.MAGENTA);
- g.drawPolygon(p);
- }
- public static void main(String[] args) {
- // TODO code application logic here
- new aula3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement