Está en la página 1de 2

import import import import

javax.swing.JFrame; javax.swing.JOptionPane; java.awt.Graphics; javax.swing.JPanel;

public class PruebaFiguras { public static void main( String args[] ) { String entrada = JOptionPane.showInputDialog("Escriba 1 para espiral con r ectangulos\n"+"Escriba 2 para dibujar una espiral circular"); int opcion = Integer.parseInt( entrada ); Figuras panel = new Figuras( opcion ); JFrame aplicacion = new JFrame(); aplicacion.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); aplicacion.add( panel ); aplicacion.setSize( 400, 400 ); aplicacion.setVisible( true ); } } class Figuras extends JPanel { private int opcion; public Figuras( int opcionUsuario ) { opcion = opcionUsuario; } public void paintComponent( Graphics g ) { super.paintComponent( g ); switch (opcion) { case 1: // dibuja espiral cuadrada int x=180, y=180, suma=0, sumando=0, signo=1, cont=0; for (int i = 0; i<15; i++) { if(i%2!=0) { suma=suma+30; sumando=suma*-1; g.drawLine (x,y, x, y+sumando); y=y+sumando; g.drawLine (x,y, x+sumando, y); x=x+sumando; } else { suma=suma+30; sumando=suma*1; g.drawLine (x,y, x, y+sumando); y=y+sumando; g.drawLine (x,y, x+sumando, y); x=x+sumando; } } break; case 2: // dibuja espiral for(int i=0; i<3600; i++)

{ g.drawArc( 0+((int)Math.round(i*0.1)), 0+((int) Math.round(i* 0.1)), (int) Math.round(360-(int)i*0.2), (int) Math.round(360-(int)i*0.2), i, 1) ; } break; } } }

También podría gustarte