no uses netbeans no estas listo para netbeans tu mismo te estas asiendo daño cambiate a blog de notas primero
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
//para hacer un bucle una cantidad de veces determinada
int cantidad;
//para saber la cantiada de elementos que tiene un arreglo
cantidad = miArreglo.lenght;
for (int contador =1;contador<=cantidad;c++){
//recuerda que el contador va tomamdo los valores 1 ,2,3,asi asta la cantidad determinada
}
PrintWriter printwriter = new PrintWriter(
new FileWriter("c:\\usuarios.txt", true));
printwriter.println(dnia.getText() + "\n");
printwriter.println(noma.getText() + "\n");
printwriter.println(apea.getText() + "\n");
printwriter.flush();
printwriter.close();
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package personas;
/**
*
* @author usuario
*/
import java.io.*;
//LOS ERRORES EMPIEZAN DESDE AQUÍ
public class ficherosgui extends javax.swing.JFrame {
public ficherosgui() {
initComponents();
}
/** 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() {
jTabbedPane1 = new javax.swing.JTabbedPane();
Altas = new javax.swing.JPanel();
LimpiarAltas = new javax.swing.JButton();
AltasButton = new javax.swing.JButton();
telefa = new javax.swing.JTextField();
apea = new javax.swing.JTextField();
noma = new javax.swing.JTextField();
Telefono = new javax.swing.JLabel();
Apellido = new javax.swing.JLabel();
Nombre = new javax.swing.JLabel();
DNI = new javax.swing.JLabel();
dnia = new javax.swing.JTextField();
Consultas = new javax.swing.JPanel();
DNIc = new javax.swing.JLabel();
Nombrec = new javax.swing.JLabel();
Apellidoc = new javax.swing.JLabel();
Telefonoc = new javax.swing.JLabel();
dnic = new javax.swing.JTextField();
nomc = new javax.swing.JTextField();
apec = new javax.swing.JTextField();
ConsultaButton = new javax.swing.JButton();
Limpiarc = new javax.swing.JButton();
telefc = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
LimpiarAltas.setText("Limpiar");
LimpiarAltas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LimpiarAltasActionPerformed(evt);
}
});
AltasButton.setText("Altas");
AltasButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AltasButtonActionPerformed(evt);
}
});
telefa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
telefaActionPerformed(evt);
}
});
noma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nomaActionPerformed(evt);
}
});
Telefono.setText("Teléfono");
Apellido.setText("Apellido");
Nombre.setText("Nombre");
DNI.setText("DNI");
javax.swing.GroupLayout AltasLayout = new javax.swing.GroupLayout(Altas);
Altas.setLayout(AltasLayout);
AltasLayout.setHorizontalGroup(
AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(AltasLayout.createSequentialGroup().addGap(70, 70, 70).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(Telefono).addGroup(AltasLayout.createSequentialGroup().addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(DNI, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(AltasButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(117, 117, 117).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(LimpiarAltas, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(telefa, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE).addComponent(noma).addComponent(dnia, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE).addComponent(apea)))).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(Nombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(Apellido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))).addContainerGap()));
AltasLayout.setVerticalGroup(
AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(AltasLayout.createSequentialGroup().addGap(44, 44, 44).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(DNI).addComponent(dnia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(50, 50, 50).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(Nombre).addComponent(noma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(35, 35, 35).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(Apellido).addComponent(apea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(38, 38, 38).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(Telefono).addComponent(telefa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(58, 58, 58).addGroup(AltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(AltasButton, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE).addComponent(LimpiarAltas, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(59, 59, 59)));
jTabbedPane1.addTab("Altas", Altas);
DNIc.setText("DNI");
Nombrec.setText("Nombre");
Apellidoc.setText("Apellido");
Telefonoc.setText("Teléfono");
dnic.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dnicActionPerformed(evt);
}
});
apec.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
apecActionPerformed(evt);
}
});
ConsultaButton.setText("Consultar");
ConsultaButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ConsultaButtonActionPerformed(evt);
}
});
Limpiarc.setText("Limpiar");
Limpiarc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LimpiarcActionPerformed(evt);
}
});
javax.swing.GroupLayout ConsultasLayout = new javax.swing.GroupLayout(Consultas);
Consultas.setLayout(ConsultasLayout);
ConsultasLayout.setHorizontalGroup(
ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ConsultasLayout.createSequentialGroup().addGap(64, 64, 64).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(Nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(DNIc).addComponent(Apellidoc, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(Telefonoc)).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(ConsultasLayout.createSequentialGroup().addGap(13, 13, 13).addComponent(dnic, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(ConsultasLayout.createSequentialGroup().addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(nomc, javax.swing.GroupLayout.Alignment.LEADING).addComponent(telefc, javax.swing.GroupLayout.Alignment.LEADING).addComponent(apec, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)))).addGap(69, 69, 69).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(ConsultaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(Limpiarc, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(45, Short.MAX_VALUE)));
ConsultasLayout.setVerticalGroup(
ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ConsultasLayout.createSequentialGroup().addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(ConsultasLayout.createSequentialGroup().addGap(46, 46, 46).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(DNIc).addComponent(dnic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(Nombrec).addComponent(nomc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(30, 30, 30)).addGroup(ConsultasLayout.createSequentialGroup().addGap(48, 48, 48).addComponent(ConsultaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(59, 59, 59))).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addGroup(ConsultasLayout.createSequentialGroup().addComponent(Limpiarc, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ConsultasLayout.createSequentialGroup().addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(Apellidoc).addComponent(apec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(31, 31, 31).addGroup(ConsultasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(Telefonoc).addComponent(telefc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(162, 162, 162)))));
jTabbedPane1.addTab("Consultas", Consultas);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 477, javax.swing.GroupLayout.PREFERRED_SIZE));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE));
pack();
}// </editor-fold>
private void LimpiarAltasActionPerformed(java.awt.event.ActionEvent evt) {
String a = " ";
dnia.setText(a);
noma.setText(a);
apea.setText(a);
telefa.setText(a);
}
private void AltasButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
BufferedWriter bufferedwriter = new BufferedWriter(
new FileWriter("c:\\usuarios.txt"));
bufferedwriter.append(dnia.getText());
bufferedwriter.flush();
bufferedwriter.newLine();
bufferedwriter.append(noma.getText());
bufferedwriter.flush();
bufferedwriter.newLine();
bufferedwriter.append(apea.getText());
bufferedwriter.flush();
bufferedwriter.newLine();
bufferedwriter.append(telefa.getText());
bufferedwriter.flush();
bufferedwriter.newLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void nomaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void telefaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void dnicActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void apecActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ConsultaButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\usuarios.txt"));
String read = " ";
String request = "";
while ((read = bufferedReader.readLine()) != null) {
if (read.substring(read.lastIndexOf(" ")).trim().equals(request)) {
System.out.println("-" + read);
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO add your handling code here:
}
private void LimpiarcActionPerformed(java.awt.event.ActionEvent evt) {
String a = " ";
dnic.setText(a);
nomc.setText(a);
apec.setText(a);
telefc.setText(a);
} // TODO add your handling code here:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
(new ficherosgui()).setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel Altas;
private javax.swing.JButton AltasButton;
private javax.swing.JLabel Apellido;
private javax.swing.JLabel Apellidoc;
private javax.swing.JButton ConsultaButton;
private javax.swing.JPanel Consultas;
private javax.swing.JLabel DNI;
private javax.swing.JLabel DNIc;
private javax.swing.JButton LimpiarAltas;
private javax.swing.JButton Limpiarc;
private javax.swing.JLabel Nombre;
private javax.swing.JLabel Nombrec;
private javax.swing.JLabel Telefono;
private javax.swing.JLabel Telefonoc;
private javax.swing.JTextField apea;
private javax.swing.JTextField apec;
private javax.swing.JTextField dnia;
private javax.swing.JTextField dnic;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextField noma;
private javax.swing.JTextField nomc;
private javax.swing.JTextField telefa;
private javax.swing.JTextField telefc;
// End of variables declaration
}