Advertisement
Guest User

SegundaYMedio

a guest
Dec 1st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.FlowLayout;
  3. import java.awt.Graphics;
  4. import java.awt.GridBagLayout;
  5. import java.awt.Paint;
  6. import java.awt.Polygon;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9.  
  10. import javax.sound.midi.Instrument;
  11. import javax.swing.BoxLayout;
  12. import javax.swing.GroupLayout;
  13. import javax.swing.JFrame;
  14. public class SegundoYMedio extends JFrame{
  15.     private ArrayList<Integer> lados = new ArrayList<Integer>();
  16.     private ArrayList<Integer> numCir = new ArrayList<Integer>();
  17.     private ArrayList<Integer> circ = new ArrayList<Integer>();
  18.     private ArrayList<String> colores = new ArrayList<String>();
  19.     private ArrayList <Color> color = new ArrayList<Color>();
  20.     private String compararStr="";
  21.     private String[] instrucciones;
  22.     private Polygon poly = new Polygon();
  23.     public SegundoYMedio(StringBuffer texto, StringBuffer radio){
  24.         setVisible(true);
  25.         setSize(600,500);
  26.         setLayout(new FlowLayout());
  27.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.         String xm=texto.toString();
  29.         instrucciones=xm.split("");
  30.         for (int i = 0; i < instrucciones.length; i++) {
  31.             compararStr=instrucciones[i].toString();
  32.             if(compararStr.equals("C")){   
  33.                 circ.add(i+1);
  34.                 numCir.add(Integer.parseInt(instrucciones[i+1]));
  35.                 i++;
  36.             }else{
  37.                 try {
  38.                     lados.add(Integer.parseInt(instrucciones[i]));
  39.                 } catch (Exception e) {
  40.                     colores.add(instrucciones[i].toString());
  41.                 }
  42.             }
  43.         }  
  44.     }
  45.     public void paint(Graphics g){
  46.         for (int i = 0; i < lados.size(); i++) {
  47.             double alfa;
  48.             int a,b;
  49.            
  50.             alfa=2*Math.PI/lados.get(i);
  51.             compararStr=colores.get(i).toString();
  52.             if (compararStr.equals("Z")) {
  53.                 color.add(Color.blue);
  54.             }else{
  55.                 if(compararStr.equals("R")){
  56.                     color.add(Color.red);
  57.                 }else{
  58.                     if(compararStr.equals("A")){
  59.                         color.add(Color.yellow);
  60.                     }else{
  61.                         if (compararStr.equals("V")) {
  62.                             color.add(Color.green);
  63.                         }else{
  64.                             if (compararStr.equals("M")) {
  65.                                 color.add(new Color(76, 40, 130));
  66.                             }else{
  67.                                 if (compararStr.equals("F")) {
  68.                                     color.add(new Color(150,75,0));
  69.                                 }else{
  70.                                     if (compararStr.equals("G")) {
  71.                                         color.add(Color.magenta);
  72.                                     }else{
  73.                                         if (compararStr.equals("T")) {
  74.                                             color.add(new Color(48,213,200));
  75.                                         }else{
  76.                                             if (compararStr.equals("S")) {
  77.                                                 color.add(new Color(19,101,134));
  78.                                             }else{
  79.                                                 if(compararStr.equals("s")){
  80.                                                     color.add(Color.orange);
  81.                                                 }
  82.                                             }
  83.                                         }
  84.                                     }
  85.                                 }
  86.                             }
  87.                         }
  88.                     }
  89.                 }
  90.             }
  91.             for (int j = 0; j < lados.get(i); j++) {
  92.                 a=400+(int)(250*Math.cos((j)*alfa));
  93.                 b=400+(int)(250*Math.sin((j)*alfa));
  94.                 poly.addPoint(a, b);
  95.             }
  96.         }
  97.         new TerceraVentana(poly, color);
  98.         hide();
  99.     }
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement