import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; class SaveListenerNew implements ActionListener { private JFrame gui; // constructor public SaveListenerNew(JFrame guiref) { gui = guiref; } // method required by action listener interface public void actionPerformed(ActionEvent e) { try { System.out.println("AQUI SE HACE TODA LA OPERACION DE GUARDADO DE UN PACIENTE"); JPanel contentPane = (JPanel)(gui.getContentPane()); // El índice 0 indica el componente splitV JSplitPane principalPane = (JSplitPane)contentPane.getComponent(0); // pane1 - personalPane2 // pane2a - objectivePane2 // pane2b - subjectivePane personalPane2 pane1 = (personalPane2)(principalPane.getTopComponent()); JSplitPane pane2 = (JSplitPane)(principalPane.getBottomComponent()); objectivePane pane2a = (objectivePane)(pane2.getLeftComponent()); subjectivePane pane2b = (subjectivePane)(pane2.getRightComponent()); String[] datos = new String[16]; datos[0] = pane1.fieldNombre.getText(); datos[1] = pane1.fieldRut.getText(); datos[2] = pane1.fieldVerificador.getText(); datos[3] = pane1.fieldNacimientoD.getText(); datos[4] = pane1.fieldNacimientoM.getText(); datos[5] = pane1.fieldNacimientoA.getText(); if(pane1.masculino.isSelected()) datos[10] = pane1.masculino.getText(); if(pane1.femenino.isSelected()) datos[10] = pane1.femenino.getText(); datos[7] = pane1.fieldDomicilio.getText(); datos[8] = pane1.fieldCiudad.getText(); datos[9] = pane1.fieldFono1.getText(); datos[6] = pane1.fieldPrevision.getText(); datos[11] = pane1.fieldFono2.getText(); datos[12] = pane1.fieldRut.getText() + "d"; datos[13] = pane1.fieldRut.getText() + "t"; datos[14] = pane1.fieldRut.getText() + "c"; datos[15] = pane1.fieldRut.getText() + "s"; for(int i=0; i<10; i++) { if(datos[i].equals("")) { JOptionPane.showMessageDialog(null,"Los siguientes datos son obigatorios:\n Nombre, RUT, Fecha de Nacimiento, Domicilio, Ciudad, Telefono1, Prevision\nRevise el problema", "Advertencia", JOptionPane.WARNING_MESSAGE); return; } } dataBase data = new dataBase(); if(data.getPersonalData(datos[1])) { JOptionPane.showMessageDialog(null,"El RUT del paciente ya existe.\nRevise el problema", "Advertencia", JOptionPane.WARNING_MESSAGE); } else { Calendar cal = Calendar.getInstance(); int mes = cal.get(Calendar.MONTH); mes = mes+1; String fecha = (cal.get(Calendar.DAY_OF_MONTH)+"/"+mes+"/"+cal.get(Calendar.YEAR)); File outputFile1 = new File(pane1.fieldRut.getText()+"c"); File outputFile2 = new File(pane1.fieldRut.getText()+"d"); File outputFile3 = new File(pane1.fieldRut.getText()+"t"); FileWriter out1 = new FileWriter(outputFile1); FileWriter out2 = new FileWriter(outputFile2); FileWriter out3 = new FileWriter(outputFile3); out1.write(pane2a.comentariosArea.getText()); out2.write(fecha+"\n"+pane2b.area1.getText()); out3.write(fecha+"\n"+pane2b.area2.getText()); out1.close(); out2.close(); out3.close(); String encabezado = "FECHA\tPA\tPC\tTC" ; String inferior = ("\n"+fecha +"\t"+pane2b.campo1.getText() +"\t"+pane2b.campo2.getText() +"\t"+pane2b.campo3.getText()); File outputFile4 = new File(pane1.fieldRut.getText()+"s"); FileWriter out4 = new FileWriter(outputFile4); out4.write(encabezado+inferior); out4.close(); data.setAll(datos); } } catch(Exception d) { System.out.println(d); } } }