Foros del Web » Programación para mayores de 30 ;) » Java »

Como dividir este applet

Estas en el tema de Como dividir este applet en el foro de Java en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 27/12/2012, 07:10
 
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. }
  #2 (permalink)  
Antiguo 27/12/2012, 07:11
 
Fecha de Ingreso: diciembre-2009
Ubicación: Santiago, Chile
Mensajes: 143
Antigüedad: 14 años, 4 meses
Puntos: 2
Respuesta: Como dividir este applet

acá esta la segunda classe

2-tarea1.java
Código java:
Ver original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package Applet;
  6.  
  7. import java.applet.Applet;
  8. import java.awt.*;
  9.  
  10.  
  11. public class Tarea1 extends Applet {
  12.     Tarea1Cls t1=new Tarea1Cls();
  13.     int f=0;
  14.     TextField txt1,txt2,txt3;
  15.     Button b8;
  16.    
  17.  @Override
  18.     public void init() {
  19.        resize(600,600);    
  20.      
  21.         Button b1,b2,b3,b4,b5,b6,b7;
  22.  
  23.         setLayout(null);
  24.         b1=new Button("Choque");  
  25.         add(b1);
  26.         b1.setBounds(10, 10, 60, 20);
  27.        
  28.         b2=new Button("Flecha");  
  29.         add(b2);
  30.         b2.setBounds(80, 10, 60, 20);
  31.        
  32.         b3=new Button("Planeta");  
  33.         add(b3);
  34.         b3.setBounds(150, 10, 60, 20);
  35.        
  36.         b4=new Button("Cuadrado");  
  37.         add(b4);
  38.         b4.setBounds(220, 10, 60, 20);
  39.        
  40.         b5=new Button("Onda");  
  41.         add(b5);
  42.         b5.setBounds(290, 10, 60, 20);
  43.        
  44.         b6=new Button("Colores");  
  45.         add(b6);
  46.         b6.setBounds(360, 10, 60, 20);
  47.        
  48.         b7=new Button("Barras");  
  49.         add(b7);
  50.         b7.setBounds(430, 10, 60, 20);
  51.        
  52.         b8=new Button("Calcular");  
  53.         add(b8);
  54.         b8.setBounds(250, 40, 60, 20);
  55.        
  56.        
  57.          
  58.         txt1=new TextField("", 10);
  59.         add(txt1);
  60.         txt1.setBounds(10, 40, 50, 20);
  61.         txt1.setVisible(false);
  62.        
  63.         txt2=new TextField("", 10);
  64.         add(txt2);
  65.         txt2.setBounds(70, 40, 50, 20);
  66.         txt2.setVisible(false);
  67.        
  68.         txt3=new TextField("", 10);
  69.         add(txt3);
  70.         txt3.setBounds(130, 40, 50, 20);
  71.         txt3.setVisible(false);
  72.        
  73.         b8.setVisible(false);    
  74.     }
  75.    
  76.     @Override
  77.     public void paint(Graphics g) {
  78.        
  79.        if (f!=8 && f!=7) {
  80.             txt1.setVisible(false);
  81.             txt2.setVisible(false);
  82.             txt3.setVisible(false);
  83.             b8.setVisible(false);
  84.        }
  85.        
  86.        switch(f) {
  87.            case 0:
  88.                 break;
  89.            case 1:
  90.                t1.Pantalla_Tarea1(g);
  91.                break;
  92.            case 2:
  93.                t1.Pantalla_Tarea2(g);
  94.                break;
  95.            case 3:
  96.                t1.Pantalla_Tarea3(g);    
  97.                break;
  98.            case 4:
  99.                t1.Pantalla_Tarea4(g);
  100.                break;
  101.            case 5:
  102.                t1.Pantalla_Tarea5(g);              
  103.                break;              
  104.            case 6:
  105.                t1.Pantalla_Tarea6(g);              
  106.                break;
  107.            case 7:
  108.                 txt1.setVisible(true);
  109.                 txt2.setVisible(true);
  110.                 txt3.setVisible(true);
  111.                 b8.setVisible(true);
  112.                 txt1.setText("");
  113.                 txt2.setText("");
  114.                 txt3.setText("");                
  115.                break;  
  116.            case 8:
  117.                t1.Pantalla_Tarea7(g,txt1,txt2,txt3);              
  118.                break;                
  119.            default:
  120.                g.drawString("Función no implementada.",40,40);
  121.        }
  122.              
  123.        f=0;      
  124.    
  125.        
  126.        
  127.    }
  128.     @Override
  129.     public boolean action(Event evt, Object arg) {        
  130.        
  131.             if (arg== "Choque") {f=1;}
  132.             if (arg== "Flecha") {f=2;}
  133.             if (arg== "Planeta") {f=3;}  
  134.             if (arg== "Cuadrado") {f=4;}  
  135.             if (arg== "Onda") {f=5;}  
  136.             if (arg== "Colores") {f=6;}  
  137.             if (arg== "Barras") {f=7;}
  138.             if (arg== "Calcular") {f=8;}  
  139.            
  140.  
  141.             repaint();
  142.             return true;
  143.     }
  144.  
  145. }

Etiquetas: applet, clase, dividir, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:51.