Por la presente para pedirles ayuda se trata de un pequeño programa utlilizando el componente java.swing formularios, lo que deseo es añadir dos botones mas un boton de guardar y otro boton de leer la idea es que cuando presiono el boton de guardar me guarde todo lo que ingreso en este pequeño programa en un directorio del disco duro luego cuando presion el boton de leer que me abre el archivo guardado en el disco duro aca pongo asu disposicion el codigo fuente por favor nesecito sus ayuda aresolever y agregar codigo fuente en el boton guardar y leer
//Programa que permite el ingreso de datos luego visualiza en un textArea
package Swing;
import javax.swing.JOptionPane;
public class IngresoDatos extends javax.swing.JFrame {
public IngresoDatos() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
grupSexo = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtApePat = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtApeMat = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtNombres = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
cboEstCivil = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
optSexM = new javax.swing.JRadioButton();
optSexF = new javax.swing.JRadioButton();
btGuardar = new javax.swing.JButton();
btnSair = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
txtLista = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Formulario de Ingreso de Datos");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Personales"));
jLabel1.setText("Apeliido Paterno:");
jLabel2.setText("Apellido Materno:");
jLabel3.setText("Nombres:");
jLabel4.setText("Estado Civil FGFDG FDFGFDGD :");
jLabel4.getAccessibleContext().setAccessibleName("Estado Civil FGJDFGFDG FDG\u00d1LDFGMDF:");
cboEstCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel2.setBackground(new java.awt.Color(255, 255, 255));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Sexo"));
grupSexo.add(optSexM);
optSexM.setText("Masculino");
optSexM.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
optSexM.setMargin(new java.awt.Insets(0, 0, 0, 0));
grupSexo.add(optSexF);
optSexF.setText("Femenino");
optSexF.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
optSexF.setMargin(new java.awt.Insets(0, 0, 0, 0));
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(32, 32, 32)
.add(optSexM)
.add(32, 32, 32)
.add(optSexF)
.addContainerGap(57, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(optSexM)
.add(optSexF))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(71, 71, 71)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel3)
.add(jLabel1)
.add(jLabel2))
.add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(txtApeMat, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
.add(txtNombres, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
.add(jPanel1Layout.createSequentialGroup()
.add(cboEstCivil, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 174, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 46, Short.MAX_VALUE))
.add(txtApePat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 220, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(43, 43, 43)))
.add(24, 24, 24))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(txtApePat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(jLabel2)
.add(txtApeMat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(jLabel3)
.add(txtNombres, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(cboEstCivil, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(52, 52, 52))
);
btGuardar.setText("Guardar");
btGuardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btGuardarActionPerformed(evt);
}
});
btnSair.setLabel("Salir");
btnSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSairActionPerformed(evt);
}
});
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Listado"));
txtLista.setColumns(20);
txtLista.setRows(5);
org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.add(txtLista, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.add(txtLista, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 126, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(36, Short.MAX_VALUE))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(btGuardar)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 347, Short.MAX_VALUE)
.add(btnSair))
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 241, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btGuardar)
.add(btnSair))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
if(evt.equals(btnSair))
System.exit(0);
}//GEN-LAST:event_btnSairActionPerformed
private void btGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btGuardarActionPerformed
//validando entradas
String data="";
if (txtApePat.getText().equals("")){
JOptionPane.showMessageDialog(null,"Ingrese Apellido Paterno");
return;
}
if (txtApeMat.getText().equals("")){
JOptionPane.showMessageDialog(null,"Ingrese Apellido Materno");
return;
}
if (txtNombres.getText().equals("")){
JOptionPane.showMessageDialog(null,"Ingrese Nombres");
return;
}
//grabamos
data = txtLista.getText() + txtApePat.getText() + " " + txtApeMat.getText() +
" "+txtNombres.getText() + " " + cboEstCivil.getSelectedItem();
if ( optSexM.isSelected() )
data += " Masculino";
else
data += " Femenino";
txtLista.setText(data+"\n");
}//GEN-LAST:event_btGuardarActionPerformed
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
cboEstCivil.removeAllItems();
cboEstCivil.addItem("Soltero");
cboEstCivil.addItem("Casado");
cboEstCivil.addItem("Divorciado");
cboEstCivil.addItem("Viudo");
}//GEN-LAST:event_formWindowOpened
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new IngresoDatos().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btGuardar;
private javax.swing.JButton btnSair;
private javax.swing.JComboBox cboEstCivil;
private javax.swing.ButtonGroup grupSexo;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JRadioButton optSexF;
private javax.swing.JRadioButton optSexM;
private javax.swing.JTextField txtApeMat;
private javax.swing.JTextField txtApePat;
private javax.swing.JTextArea txtLista;
private javax.swing.JTextField txtNombres;
// End of variables declaration//GEN-END:variables
}