import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; class SaveListenerOld implements ActionListener { private JFrame gui; // constructor public SaveListenerOld(JFrame guiref) { gui = guiref; } // method required by action listener interface public void actionPerformed(ActionEvent e) { try { JPanel contentPane = (JPanel)(gui.getContentPane()); // El índice 0 indica el componente splitV JSplitPane principalPane = (JSplitPane)contentPane.getComponent(0); // pane1 - personalPane // pane2a - objectivePane // pane2b - subjectivePane personalPane pane1 = (personalPane)(principalPane.getTopComponent()); JSplitPane pane2 = (JSplitPane)(principalPane.getBottomComponent()); objectivePane pane2a = (objectivePane)(pane2.getLeftComponent()); subjectivePane pane2b = (subjectivePane)(pane2.getRightComponent()); String[] datos = new String[7]; if(pane1.masculino.isSelected()) datos[0] = pane1.masculino.getText(); if(pane1.femenino.isSelected()) datos[0] = pane1.femenino.getText(); datos[1] = pane1.fieldFono1.getText(); datos[6] = pane1.fieldFono2.getText(); if(datos[6].equals("")) { datos[6]="1"; System.out.println("cambio dato"); } datos[3] = pane1.fieldDomicilio.getText(); datos[4] = pane1.fieldCiudad.getText(); datos[5] = pane1.fieldPrevision.getText(); datos[2] = pane1.fieldRut.getText(); for(int i=1; i<6; 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(); 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)); String svAnt = pane2a.vitalSignsArea.getText(); String dAnt = pane2a.diagnosticoArea.getText(); String tAnt = pane2a.tratamientoArea.getText(); String cAnt = pane2a.comentariosArea.getText(); String dAct = ("\n"+fecha+":\n"+pane2b.area1.getText()); String tAct = ("\n"+fecha+":\n"+pane2b.area2.getText()); String svAct = ("\n"+fecha +"\t"+pane2b.campo1.getText() +"\t"+pane2b.campo2.getText() +"\t"+pane2b.campo3.getText()); 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(cAnt); out2.write(dAnt+dAct); out3.write(tAnt+tAct); out1.close(); out2.close(); out3.close(); File outputFile4 = new File(pane1.fieldRut.getText()+"s"); FileWriter out4 = new FileWriter(outputFile4); out4.write(svAnt+svAct); out4.close(); data.updateAll(datos); } catch(Exception d) { System.out.println(d); } } }