Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/04/2012, 13:03
Bladsmickey
 
Fecha de Ingreso: enero-2011
Mensajes: 33
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Constructores!

Es que asi es como lo hago, o al menos creo que lo hago bien, te paso mi codigo a ver si es un error que no veo:

Código Java:
Ver original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author Bladsmickey
  9.  */
  10. public class variables {
  11.     private String nombre;
  12.     private String apellido;
  13.     private String cedula;
  14.    
  15.     public void ponervariables(String nom,String ape,String cedu){
  16.     this.nombre=nom;
  17.     this.apellido=ape;
  18.     this.cedula=cedu;
  19.     }
  20.    
  21.     public String nom(){
  22. return nombre;
  23. }  
  24.     public String ape(){
  25. return apellido;
  26. }
  27.       public String cedu(){
  28. return cedula;
  29. }
  30.    
  31. }


Código Java:
Ver original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author Bladsmickey
  9.  */
  10. public class principal extends javax.swing.JFrame {
  11.  
  12.     /**
  13.      * Creates new form principal
  14.      */
  15.     public principal() {
  16.         initComponents();
  17.     }
  18.  
  19.     /**
  20.      * This method is called from within the constructor to initialize the form.
  21.      * WARNING: Do NOT modify this code. The content of this method is always
  22.      * regenerated by the Form Editor.
  23.      */
  24.     @SuppressWarnings("unchecked")
  25.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  26.     private void initComponents() {
  27.  
  28.         jButton1 = new javax.swing.JButton();
  29.         jButton2 = new javax.swing.JButton();
  30.         jLabel1 = new javax.swing.JLabel();
  31.         jLabel2 = new javax.swing.JLabel();
  32.         jLabel3 = new javax.swing.JLabel();
  33.         jTextField1 = new javax.swing.JTextField();
  34.         jTextField2 = new javax.swing.JTextField();
  35.         jTextField3 = new javax.swing.JTextField();
  36.         jMenuBar1 = new javax.swing.JMenuBar();
  37.         jMenu1 = new javax.swing.JMenu();
  38.         jMenu2 = new javax.swing.JMenu();
  39.  
  40.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  41.  
  42.         jButton1.setText("Continuar");
  43.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  44.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  45.                 jButton1ActionPerformed(evt);
  46.             }
  47.         });
  48.  
  49.         jButton2.setText("Salir");
  50.  
  51.         jLabel1.setText("Nombre");
  52.  
  53.         jLabel2.setText("Apellido");
  54.  
  55.         jLabel3.setText("Cedula");
  56.  
  57.         jMenu1.setText("File");
  58.         jMenuBar1.add(jMenu1);
  59.  
  60.         jMenu2.setText("Edit");
  61.         jMenuBar1.add(jMenu2);
  62.  
  63.         setJMenuBar(jMenuBar1);
  64.  
  65.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  66.         getContentPane().setLayout(layout);
  67.         layout.setHorizontalGroup(
  68.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  69.             .addGroup(layout.createSequentialGroup()
  70.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  71.                     .addGroup(layout.createSequentialGroup()
  72.                         .addGap(96, 96, 96)
  73.                         .addComponent(jButton1)
  74.                         .addGap(18, 18, 18)
  75.                         .addComponent(jButton2))
  76.                     .addGroup(layout.createSequentialGroup()
  77.                         .addContainerGap()
  78.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  79.                             .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  80.                                 .addComponent(jLabel1)
  81.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  82.                                 .addComponent(jTextField1))
  83.                             .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  84.                                 .addComponent(jLabel2)
  85.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  86.                                 .addComponent(jTextField2))
  87.                             .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  88.                                 .addComponent(jLabel3)
  89.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  90.                                 .addComponent(jTextField3)))))
  91.                 .addContainerGap(154, Short.MAX_VALUE))
  92.         );
  93.         layout.setVerticalGroup(
  94.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  96.                 .addContainerGap()
  97.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  98.                     .addComponent(jLabel1)
  99.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  100.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  101.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  102.                     .addComponent(jLabel2)
  103.                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  104.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  105.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  106.                     .addComponent(jLabel3)
  107.                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  108.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 149, Short.MAX_VALUE)
  109.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  110.                     .addComponent(jButton1)
  111.                     .addComponent(jButton2))
  112.                 .addGap(24, 24, 24))
  113.         );
  114.  
  115.         pack();
  116.     }// </editor-fold>
  117.  
  118.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  119.  
  120.         variables a=new variables();
  121.         a.ponervariables(jTextField1.getText(),jTextField2.getText(),jTextField3.getText());
  122.         new prueba().show();
  123.     }
  124.  
  125.     /**
  126.      * @param args the command line arguments
  127.      */
  128.     public static void main(String args[]) {
  129.         /*
  130.          * Set the Nimbus look and feel
  131.          */
  132.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  133.         /*
  134.          * If Nimbus (introduced in Java SE 6) is not available, stay with the
  135.          * default look and feel. For details see
  136.          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  137.          */
  138.         try {
  139.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  140.                 if ("Nimbus".equals(info.getName())) {
  141.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  142.                     break;
  143.                 }
  144.             }
  145.         } catch (ClassNotFoundException ex) {
  146.             java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  147.         } catch (InstantiationException ex) {
  148.             java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  149.         } catch (IllegalAccessException ex) {
  150.             java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  151.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  152.             java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  153.         }
  154.         //</editor-fold>
  155.  
  156.         /*
  157.          * Create and display the form
  158.          */
  159.         java.awt.EventQueue.invokeLater(new Runnable() {
  160.  
  161.             public void run() {
  162.                 new principal().setVisible(true);
  163.             }
  164.         });
  165.     }
  166.     // Variables declaration - do not modify
  167.     private javax.swing.JButton jButton1;
  168.     private javax.swing.JButton jButton2;
  169.     private javax.swing.JLabel jLabel1;
  170.     private javax.swing.JLabel jLabel2;
  171.     private javax.swing.JLabel jLabel3;
  172.     private javax.swing.JMenu jMenu1;
  173.     private javax.swing.JMenu jMenu2;
  174.     private javax.swing.JMenuBar jMenuBar1;
  175.     private javax.swing.JTextField jTextField1;
  176.     private javax.swing.JTextField jTextField2;
  177.     private javax.swing.JTextField jTextField3;
  178.     // End of variables declaration
  179. }


Creo que el problema esta en que las variables no se guardan, pero no se la fuente del problema.