pass information of a jtable that is in a frame to another Jframe

0

I have two windows two jframes worth. in a jframe I have a textarea that is where I want to put the ID or identification of a person .... in the other jframe I have a table with the information of the patients what I want is to search in that jframe the correct patient and from that jframe I want to pass the identification to the other jframe and I want it to be put in the textarea that I have created. my jtextarea is public and my jtable is also public.

 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sismedvista;

import cliente.BusquedaPaciente;
import javax.swing.JOptionPane;
import sismedvista.pacienteEsc; 
/**
 *
 * @author laptop
 */
public class pacienteEsc extends javax.swing.JFrame {

    String paciente = ""; 
    public pacienteEsc() {
        initComponents();
        cargarTabla("");

    }

        void cargarTabla(String cad) {
        BusquedaPaciente c = new BusquedaPaciente();
        c.CargarTabla(jTable1, cad);

    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setTitle("Buscar Paciente");
        setLocation(new java.awt.Point(480, 200));
        setPreferredSize(new java.awt.Dimension(415, 350));
        getContentPane().setLayout(null);

        jLabel2.setFont(new java.awt.Font("Roboto", 0, 11)); // NOI18N
        jLabel2.setText("Diguite la cedula del paciente:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(10, 10, 380, 14);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 70, 380, 220);

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField1KeyReleased(evt);
            }
        });
        getContentPane().add(jTextField1);
        jTextField1.setBounds(10, 30, 170, 30);
        getContentPane().add(jTextField2);
        jTextField2.setBounds(210, 30, 150, 30);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/fondo-blanco.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 400, 340);

        pack();
    }// </editor-fold>                        

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {                                        
        cargarTabla(jTextField1.getText());
    }                                       

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        int filaseleccionada = jTable1.getSelectedRow();
        String cedula = (String) jTable1.getValueAt(filaseleccionada, 0);
        //JOptionPane.showMessageDialog(null,"Tenemos seleccionado algo "+ cedula,"Mensaje",JOptionPane.INFORMATION_MESSAGE);    
        examFisi.jTextArea6.setText(cedula);

    }                                    

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(pacienteEsc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(pacienteEsc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(pacienteEsc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(pacienteEsc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new pacienteEsc().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    public static javax.swing.JTextField jTextField2;
    // End of variables declaration                   
}
    
asked by juancamilovallejos0 07.06.2018 в 16:10
source

1 answer

0

You have to call this method from a Main or a Jbutton > And the method should be in JFrame where the jtable is.

public void pasarDatos(){
           int fT = jtabla1.getRowCount();
           String paciente ="";
           double b = 0;
           int i=0;
           if(fT!=0){
           ArrayList<String> pacientes = new ArrayList<String>();
           while (fT > i) {
                Object objVT = jtabla1.getValueAt(i,6);
                add.pacientes(String.valueOf(objVT));

            }
           }
           new otroJFrame().setVisible(true);
           new otroJFrame().setDatos(pacientes);
        }

The method below is for the JFrame class (anotherJFrame) to which the data will go:

public void setDatos(List<String> datos){
  if(!datos.isEmpy()){
  Iterator iter = datos.iterator();
   while (iter.hasNext()) {
           String next = (String)iter.next();
           System.out.println(next);
          }
  }
}
    
answered by 07.06.2018 в 22:14