• Sábado 21 de Septiembre de 2024, 12:46

Autor Tema:  Applet De Un Arbol  (Leído 2383 veces)

richardroc

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Applet De Un Arbol
« en: Martes 17 de Junio de 2008, 20:58 »
0
Hola.. necesito de su ayuda, soy nuevo en Java y me dejaron un trabajo sobre la creacion de un applet en Java, pero de un Arbol.. osea eso de insertar nodos.. alguien que me pueda ayudar.. estamos usando Netbeans como lenguaje de programacion...

manix

  • Miembro MUY activo
  • ***
  • Mensajes: 203
  • Nacionalidad: cr
    • Ver Perfil
    • http://apuntes.delibertad.com
Re: Applet De Un Arbol
« Respuesta #1 en: Martes 17 de Junio de 2008, 21:01 »
0
netbeans es el IDE, no el lenguaje. Podrias empezar diciendonos como llevas ese proyecto, si ya tienes algo, descripcipn, como vas con el applet, etc

saludos

richardroc

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Re: Applet De Un Arbol
« Respuesta #2 en: Miércoles 18 de Junio de 2008, 00:44 »
0
Hola amigo gracias por corregirme es que no estoy muy metido en el mundo de java.. pero si me gustaria aprender.. por k lo veo interesante...y lo llevo avanzado como muxo esfuerzo es esto...haber si me entiendes..lo tengo en Netbeans. de esta forma..
->prjArbol
-->Source Packages
--->pkgArbol
       Arbol.java
       ClasePrincipal.java
       NodoDoble.java
       ejemplonuevo.java//este es el applet donde instancio a los demas de arriba..
///////////Arbo.java///////////////////////////////////////////
package pkgArbol;
public class Arbol {
    public NodoDoble raiz;
    Arbol(){raiz=null;}
    NodoDoble temp,nuevo_nodo,enlace;
    Paciente nuevo_paciente;
    int rpt;
    String c_a;
    String n_cod;
    //Metodo de guardar datos en el arbol
    void setGuardarDatos(String Codigo,String Nombre,String Apellido)
    {
        if (raiz==null)
        {
            nuevo_nodo=new  NodoDoble();
            nuevo_paciente =new Paciente();
            nuevo_paciente.setApellidos(Apellido);
            nuevo_paciente.setCodigo(Codigo);
            nuevo_paciente.setNombre(Nombre);
            c_a=(Codigo.substring(0,1)+Nombre.substring(0,2)+Apellido.substring(0,2));
            nuevo_paciente.setCodigoAutogenerado(c_a);
            nuevo_nodo.setUnPaciente(nuevo_paciente);
            nuevo_nodo.setApuntaAnt(null);
            nuevo_nodo.setApuntaAnt(null);
            raiz=nuevo_nodo;
           } else{
            temp=raiz;
            while (temp!=null)
            {
               temp=raiz;
                while (temp!=null)
                {
                 n_cod=temp.getUnPaciente().getCodigo();
                 enlace=temp;        
                 if (temp.getApuntaAnt()==null  )
                 { temp=temp.getApuntaSgte();    }
                 else{ temp=temp.getApuntaAnt();}              
                }
                  nuevo_nodo=new  NodoDoble();
                  nuevo_paciente =new Paciente();
                  nuevo_paciente.setApellidos(Apellido);
                  nuevo_paciente.setCodigo(Codigo);
                  nuevo_paciente.setNombre(Nombre);
                  c_a=(Codigo.substring(0,1)+Nombre.substring(0,2)+Apellido.substring(0,2));
                  nuevo_paciente.setCodigoAutogenerado(c_a);                  nuevo_paciente.setCodigoAutogenerado(Codigo.substring(1,1)+Nombre.substring(1,1)+Apellido.substring(1,2));
                  nuevo_nodo.setUnPaciente(nuevo_paciente);
                  nuevo_nodo.setApuntaAnt(null);
                  nuevo_nodo.setApuntaAnt(null);
                  rpt=n_cod.compareTo(Codigo);
                  if (rpt< 0)
                  { enlace.setApuntaSgte(nuevo_nodo);  }
                  else{enlace.setApuntaAnt(nuevo_nodo);            }              
            }            
           }
    }
    //Metodo para reportar datos del arbol
       void reportar()
    {      
        temp=raiz;
    int c=0;
        while (temp!=null)
        {
             nuevo_paciente=temp.getUnPaciente();
             System.out.println(nuevo_paciente.getCodigoAutogenerado() + ' '+nuevo_paciente.getCodigo() + ' '+nuevo_paciente.getApellidos()+' '+nuevo_paciente.getNombre()  );
                             
                 if (temp.getApuntaAnt()==null  )
                 { temp=temp.getApuntaSgte();    }
                 else{ temp=temp.getApuntaAnt();}    
             c++;
        }
        // IMPLEMENTAR CODIGO AQUI
       
    } // IMPLEMENTAR CODIGO AQUI
  }
/////////////////ClasePrincipal/////////////////////
package pkgArbol;
import java.io.*;
public class ClasePrincipal {
    public static void main(String[] args)throws IOException  {
        BufferedReader leer=new BufferedReader(new InputStreamReader(System.in ));
    Arbol nodo = new Arbol();
//         nodo.setGuardarDatos("44", "primer nombre", "primer apellido");
//         nodo.setGuardarDatos("24", "segundo nombre", "segundo apellido");
//         nodo.setGuardarDatos("333", "Tercer nombre", "tercer apallido");
        int c=0;
        while (c==0 || c==1)
        {
         if (c==0);
         {
           System.out.println(" \t\t\t          MENU          ");
           System.out.println("\t\t\tingrese 0 para insertar Nuevo nodo: ");
           System.out.println("\t\t\tingrese 1 para ver Reporte: ");
           System.out.println("\t\t\tingrese cualquier numero para salir: ");
            c=  Integer.parseInt(leer.readLine() );
            if (c==1)
            {
                if (nodo.reportar()==0 )
                {
                           System.out.println("Lista Vacia");
                }
                else
                {
                           System.out.println("C autog. || cod ||nombre  y Apellido");
                }
            }
            else{
             if (c==0)
            {
                System.out.println("\tIngrese Codigo: ");
                String cod=leer.readLine();
                System.out.println("\tIngrese Noombre: ");
                String nom=leer.readLine();
                System.out.println("\tIngrese Apellido: ");
                String ape=leer.readLine();
                nodo.setGuardarDatos(cod,nom, ape);          
            }  
            }                  
         }    
        }    
    }
}
//////////////////////////////////NodoDoble.java////////////////////////
package pkgArbol;
public class NodoDoble {
    private Paciente unPaciente;
    private NodoDoble ApuntaSgte;
    private NodoDoble ApuntaAnt;
    void setUnPaciente(Paciente punPaciente)
    {
        unPaciente=punPaciente;
    }
    void setApuntaSgte(NodoDoble pApuntaSgte)
    {
        ApuntaSgte=pApuntaSgte;
    }
    void setApuntaAnt(NodoDoble pApuntaAnt)
    {
        ApuntaAnt=pApuntaAnt;
    }
    Paciente getUnPaciente(){return unPaciente;}
    NodoDoble getApuntaSgte(){return ApuntaSgte;}
    NodoDoble getApuntaAnt(){return ApuntaAnt;}
}
//////////////////////////ejemplonuevo.java//////////////////////////////
package pkgArbol;
public class ejemplonuevo extends javax.swing.JApplet {
    Arbol nodo = new Arbol();
            public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }      
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        txtcod = new javax.swing.JTextField();
        txtnom = new javax.swing.JTextField();
        txtape = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnrep = new javax.swing.JButton();
        btnagre = new javax.swing.JButton();
        lstape = new java.awt.List();
        jLabel4 = new javax.swing.JLabel();
        lstcoda = new java.awt.List();
        lstcod = new java.awt.List();
        lstnom = new java.awt.List();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        getContentPane().setLayout(null);
        getContentPane().add(txtcod);
        txtcod.setBounds(110, 40, 180, 27);

        txtnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnomActionPerformed(evt);
            }
        });
        getContentPane().add(txtnom);
        txtnom.setBounds(110, 80, 210, 27);
        getContentPane().add(txtape);
        txtape.setBounds(110, 120, 210, 27);

        jLabel1.setText("Apellido");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(410, 210, 50, 20);

        jLabel2.setText("Nombre");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(50, 90, 52, 17);

        jLabel3.setText("Apellido");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(50, 120, 50, 17);

        btnrep.setText("Reportar");
        btnrep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnrepActionPerformed(evt);
            }
        });
        getContentPane().add(btnrep);
        btnrep.setBounds(170, 160, 150, 29);

        btnagre.setText("Agregar");
        btnagre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnagreActionPerformed(evt);
            }
        });
        getContentPane().add(btnagre);
        btnagre.setBounds(10, 160, 130, 29);
        getContentPane().add(lstape);
        lstape.setBounds(350, 230, 200, 140);

        jLabel4.setText("Codigo");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(50, 50, 44, 17);

        lstcoda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lstcodaActionPerformed(evt);
            }
        });
        getContentPane().add(lstcoda);
        lstcoda.setBounds(10, 230, 80, 140);
        getContentPane().add(lstcod);
        lstcod.setBounds(90, 230, 100, 140);
        getContentPane().add(lstnom);
        lstnom.setBounds(190, 230, 160, 140);

        jLabel5.setText("Codigo Auto");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(10, 210, 80, 17);

        jLabel6.setText("nombre");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(250, 210, 50, 20);

        jLabel7.setText("Codigo");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(120, 210, 44, 17);
    }// </editor-fold>                        
    private void txtnomActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
    }                                      
            void reportar()
    {            
        nodo.temp=nodo.raiz;
    int c=0;
        while (nodo.temp!=null)
        {
           nodo.nuevo_paciente=nodo.temp.getUnPaciente();
             //System.out.println(nuevo_paciente.getCodigoAutogenerado() + ' '+nuevo_paciente.getCodigo() + ' '+nuevo_paciente.getApellidos()+' '+nuevo_paciente.getNombre()  );
                 this.lstcoda.add(nodo.nuevo_paciente.getCodigoAutogenerado());          
                 this.lstcod.add(nodo.nuevo_paciente.getCodigo());          
                 this.lstnom.add(nodo.nuevo_paciente.getNombre() );          
                 this.lstape.add(nodo.nuevo_paciente.getApellidos() );          
                 
                 if (nodo.temp.getApuntaAnt()==null  )
                 {nodo.temp=nodo.temp.getApuntaSgte();    }
                 else{ nodo.temp=nodo.temp.getApuntaAnt();}    
             c++;
        }
       
        // IMPLEMENTAR CODIGO AQUI
       
    } // IMPLEMENTAR CODIGO AQUI
    private void btnrepActionPerformed(java.awt.event.ActionEvent evt) {                                      
 
this.reportar();      
 
}                                      

    private void btnagreActionPerformed(java.awt.event.ActionEvent evt) {                                        
       
        String cod=this.txtcod.getText();
        String nom=this.txtnom.getText();
        String ape=this.txtape.getText();
        nodo.setGuardarDatos(cod, nom,ape);
       
    }                                      

    private void lstcodaActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
}                                      
   
   
    // Variables declaration - do not modify                    
    private javax.swing.JButton btnagre;
    private javax.swing.JButton btnrep;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private java.awt.List lstape;
    private java.awt.List lstcod;
    private java.awt.List lstcoda;
    private java.awt.List lstnom;
    private javax.swing.JTextField txtape;
    private javax.swing.JTextField txtcod;
    private javax.swing.JTextField txtnom;
    // End of variables declaration                  
   
}
El mensaje contiene 1 archivo adjunto. Debes ingresar o registrarte para poder verlo y descargarlo.

manix

  • Miembro MUY activo
  • ***
  • Mensajes: 203
  • Nacionalidad: cr
    • Ver Perfil
    • http://apuntes.delibertad.com
Re: Applet De Un Arbol
« Respuesta #3 en: Miércoles 18 de Junio de 2008, 00:48 »
0
y cual es el problema exactamente?

saludos

richardroc

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Re: Applet De Un Arbol
« Respuesta #4 en: Miércoles 18 de Junio de 2008, 01:20 »
0
me falta poner un comand donde pueda hacer una busqueda, y que me reporte tmb y tmb una observacion tuia por fa.....