Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/12/2012, 07:10
Rasec101
 
Fecha de Ingreso: diciembre-2009
Ubicación: Santiago, Chile
Mensajes: 143
Antigüedad: 14 años, 4 meses
Puntos: 2
Como dividir este applet

Buen dia mi duda es la siguiente estoy comensando con java y e creado un applet con 7 ejercicios dentro de 2 classes ahora necesito dividir estas dos clases por cada ejercicio es decir los 7 ejercicios por separado pero me quede bloqueado y no se por donde comenzar espero aberme esplicado bien aca dejo el codigo para ver si me pueden dar una idea.
1-Tarea1Cls.java
Código java:
Ver original
  1. package Applet;
  2. import java.awt.*;
  3. import java.util.Arrays;
  4. public class Tarea1Cls {
  5.    
  6.  public void Pantalla_Tarea3(Graphics g){
  7.      //planeta
  8.      int cx,cy,a,aa;
  9.      double r,r2,y,x;
  10.      
  11.      Limpia_Pantalla(g);
  12.      r=100;r2=150;
  13.      cx=300;
  14.      cy=300;
  15.      x=300;
  16.      y=300;    
  17.         for( a=0,aa=100; a < 50; a++,aa-- )  {
  18.  
  19.         Limpia_Pantalla(g);
  20.         g.setColor(Color.green);        
  21.         g.fillOval(300, 300, 10, 10);        
  22.        
  23.         //derecha
  24.         g.setColor(Color.red);
  25.         g.fillOval((int)x, (int)y, 10, 10);
  26.        
  27.         y=r* Math.sin( a )+cy;
  28.         x=r* Math.cos( a )+cx;
  29.        
  30.         //izquierda
  31.         g.setColor(Color.blue);
  32.         g.fillOval((int)x, (int)y, 10, 10);
  33.        
  34.         y=r2* Math.sin( aa )+cy;
  35.         x=r2* Math.cos( aa )+cx;
  36.  
  37.         pausa(200);
  38.  
  39.       // g.drawString("x:"+String.valueOf(x)+" y:"+String.valueOf(y)+"",300,300+(10*a));  
  40.  
  41.      }  
  42.     Limpia_Pantalla(g);
  43.      
  44.  }//fin Pantalla_Tarea3    
  45.    
  46.  public void Pantalla_Tarea5(Graphics g){
  47.         //Onda
  48.         int apAncho,j2;  
  49.        
  50.         apAncho = 200;  
  51.  
  52.        
  53.         for( int i=100; i < apAncho+300; i++ )
  54.             {
  55.             Limpia_Pantalla(g);
  56.             j2 = ValorY( i+1 );
  57.    
  58.             g.setColor(Color.blue);
  59.             g.fillOval(i, j2, 20, 20);
  60.  
  61.             pausa(10);
  62.            
  63.             }
  64.         Limpia_Pantalla(g);
  65.        
  66.     }//fin Pantalla_Tarea5
  67.  
  68.      private int ValorY( int valor ) {
  69.              int apAncho,apAlto;
  70.        
  71.         apAncho = 200;
  72.         apAlto = 200;
  73.          
  74.           double xmin,xmax,ymin,ymax;
  75.                  xmin = -10.0;
  76.         xmax = 10.0;
  77.         ymin = -1.0;
  78.         ymax = 1.0;
  79.         double x,y;
  80.         int retorno;
  81.  
  82.         // Cartesianas equivalentes al punto de la pantalla
  83.         x = (valor * (xmax-xmin) / (apAncho+300)) + xmin;
  84.         // Calculamos el seno de ese punto
  85.         y = Math.sin( x );
  86.         // Escalamos la coordenada y dentro de los limites de la ventana
  87.         retorno = (int)( (y-ymin) * (apAlto-100) / (ymax-ymin) );
  88.         // Reconvertinos el valor cartesiano a punto de pantalla
  89.         retorno = apAlto - retorno+100;
  90.  
  91.         return( retorno );
  92.        
  93.     }
  94.  
  95.     public void Pantalla_Tarea4(Graphics g){
  96.         //Cuadrado
  97.          Limpia_Pantalla(g);
  98.          
  99.         int x= Random(50,200);
  100.         int y= Random(50,200);
  101.         int z= Random(50,200);
  102.        
  103.          
  104.         g.drawRect(x,y,z,z);
  105.         g.drawRect(x,y,(int)(z/2),(int)(z/2));
  106.          
  107.         g.drawLine(x,(int)(y+z),(int)(x+z),y);
  108.         g.drawLine((int)(x+(z/2)),(int)(y+(z/2)),(int)(x+z),(int)(y+z));
  109.         g.drawLine((int)(x+(z/2)),(int)(y+z),(int)(x+z),(int)(y+(z/2)));
  110.        
  111.     }// Pantalla_Tarea4  
  112.    
  113.     public void Pantalla_Tarea7(Graphics g,TextField txt1,TextField txt2,TextField txt3){
  114.         //Barras
  115.          Limpia_Pantalla(g);
  116.  
  117.          int max;
  118.          double p;
  119.          int barra[]=new int[3];
  120.          
  121.          
  122.          if (isNumeric(txt1.getText())) {
  123.             barra[0]=Integer.parseInt(txt1.getText());
  124.          }
  125.          else {
  126.              barra[0]=0;
  127.          }
  128.  
  129.          if (isNumeric(txt2.getText())) {
  130.             barra[1]=Integer.parseInt(txt2.getText());
  131.          }
  132.          else {
  133.              barra[1]=0;
  134.          }
  135.          
  136.          if (isNumeric(txt3.getText())) {
  137.             barra[2]=Integer.parseInt(txt3.getText());
  138.          }
  139.          else {
  140.              barra[2]=0;
  141.          }        
  142.    
  143.  
  144.          Arrays.sort(barra);
  145.          max=barra[2];
  146.          
  147.        
  148.          
  149.          g.drawRect(80,130,340,315);
  150.        
  151.          p=Dividir((barra[0]*100),max);  
  152.          g.setColor(Color.black);
  153.          g.drawString(String.valueOf(barra[0])+" ("+String.valueOf((int)p)+"%)",90,120);        
  154.          p=(p/100)*300;          
  155.          g.setColor(Entrega_Color());
  156.          g.fillRect(90,135,100,(int)p);
  157.          
  158.        
  159.          p=Dividir((barra[1]*100),max);
  160.          g.setColor(Color.black);
  161.          g.drawString(String.valueOf(barra[1])+" ("+String.valueOf((int)p)+"%)",200,120);
  162.           p=(p/100)*300;  
  163.          g.setColor(Entrega_Color());
  164.          g.fillRect(200,135,100,(int)p);
  165.          
  166.          
  167.          p=Dividir((barra[2]*100),max);  
  168.          g.setColor(Color.black);
  169.          g.drawString(String.valueOf(barra[2])+" ("+String.valueOf((int)p)+"%)",310,120);
  170.          p=(p/100)*300;
  171.          g.setColor(Entrega_Color());
  172.          g.fillRect(310,135,100,(int)p);
  173.          
  174.          
  175.  
  176.        
  177.     }// Pantalla_Tarea7
  178.        public void Pantalla_Tarea2(Graphics g){
  179.         //flecha
  180.          Limpia_Pantalla(g);
  181.          
  182.         int vecx[]=new int[3];
  183.         int vecy[]=new int[3];
  184.        
  185.         int x= Random(130,250);
  186.         int y= Random(50,300);
  187.         int z= Random(20,80);  
  188.        
  189.        
  190.         vecx[0]=x;
  191.         vecy[0]=y-10;
  192.        
  193.         vecx[1]=x;
  194.         vecy[1]=y+z+10;
  195.        
  196.         vecx[2]=x-z;
  197.         vecy[2]=y+(z/2);
  198.        
  199.         g.setColor(Color.blue);
  200.         g.fillRect(x, y, z, z);
  201.         g.fillPolygon(vecx, vecy, 3);
  202.     }// Pantalla_Tarea2
  203.  
  204.     public void Pantalla_Tarea6(Graphics g){
  205.            //colores
  206.          Limpia_Pantalla(g);
  207.          
  208.         int x= Random(100,300);
  209.         int y= Random(100,200);
  210.         int z= Random(20,200);    
  211.        
  212.         //cuadrado mayor
  213.         g.setColor(Entrega_Color());
  214.         g.fillRect(x,y,z,z);      
  215.        
  216.         //cuadrados medios
  217.         g.setColor(Entrega_Color());
  218.         g.fillRect(x-(z/3),y-(z/3),(z/3)*2,(z/3)*2);
  219.        
  220.         g.setColor(Entrega_Color());
  221.         g.fillRect(x-(z/3),y+((z/3)*2),(z/3)*2,(z/3)*2);        
  222.  
  223.         g.setColor(Entrega_Color());
  224.         g.fillRect(x+((z/3)*2),y-(z/3),(z/3)*2,(z/3)*2);
  225.        
  226.         g.setColor(Entrega_Color());
  227.         g.fillRect(x+((z/3)*2),y+((z/3)*2),(z/3)*2,(z/3)*2);  
  228.        
  229.        
  230.        //cuadrados menores
  231.        
  232.         g.setColor(Entrega_Color());
  233.         g.fillRect(x,y,(z/3),(z/3));
  234.        
  235.         g.setColor(Entrega_Color());
  236.         g.fillRect(x,y+((z/3)*2),(z/3),(z/3));        
  237.  
  238.         g.setColor(Entrega_Color());
  239.         g.fillRect(x+((z/3)*2),y,(z/3),(z/3));
  240.        
  241.         g.setColor(Entrega_Color());
  242.         g.fillRect(x+((z/3)*2),y+((z/3)*2),(z/3),(z/3));  
  243.                
  244.  
  245.     }// Pantalla_Tarea6
  246.    
  247.     public void Pantalla_Tarea1(Graphics g){
  248.         //choque
  249.          int i,y,d;
  250.  
  251.         int ii= Random(10,50);
  252.         int yy= Random(100,300);
  253.         int zz= Random(20,80);
  254.        
  255.         int dd= ii+(zz*5);
  256.        
  257.         for ( y=0;y<3;y++) {
  258.             //a la derecha
  259.             for (i=ii,d=dd;i<(zz*2)+ii;i+=5,d-=5) {
  260.                 Limpia_Pantalla(g);
  261.                 g.setColor(Color.blue);
  262.                 g.fillOval(d,yy, zz, zz);
  263.                 g.setColor(Color.red);
  264.                 g.fillOval(i,yy, zz, zz);
  265.                 pausa(10);          
  266.             }
  267.              //a la izquierda
  268.             pausa(20);
  269.            
  270.             for (;i>ii;i-=5,d+=5) {
  271.                 Limpia_Pantalla(g);
  272.                 g.setColor(Color.blue);
  273.                 g.fillOval(d,yy, zz, zz);
  274.                 g.setColor(Color.red);
  275.                 g.fillOval(i,yy, zz, zz);
  276.                 pausa(10);          
  277.             }
  278.         }
  279.        Limpia_Pantalla(g);
  280.        
  281.     }//fin Pantalla_Tarea1
  282.    
  283.    
  284.     public void Limpia_Pantalla(Graphics g) {
  285.         g.clearRect(0, 100, 700, 700);        
  286.     }
  287.    
  288.     public double Dividir(double a,double b) {
  289.         double c;
  290.        
  291.     try {
  292.         c=a/b;
  293.         return c;
  294.     } catch (NumberFormatException nfe){
  295.         return 0;
  296.     }        
  297.     }
  298.    
  299.     public int Random(int min,int max) {
  300.        
  301.         return ((int)((Math.random()*max)+min));
  302.    
  303.     }  
  304.     public Color Entrega_Color() {
  305.  
  306.             int R=Random(0,256);
  307.             int G=Random(0,256);
  308.             int B=Random(0,256);      
  309.            
  310.             return new Color(R,G,B);
  311.     }    
  312.    
  313.   public boolean isNumeric(String cadena){
  314.     try {
  315.         Integer.parseInt(cadena);
  316.         return true;
  317.     } catch (NumberFormatException nfe){
  318.         return false;
  319.     }
  320.     }
  321.  
  322.     public void pausa(int n){
  323.        try{
  324.            Thread.sleep(n);
  325.        }catch(Exception e) {
  326.            
  327.        }
  328.     }
  329. }