Java - Problema con un txt en Java

 
Vista:
sin imagen de perfil
Val: 13
Ha aumentado su posición en 7 puestos en Java (en relación al último mes)
Gráfica de Java

Problema con un txt en Java

Publicado por Leandro (6 intervenciones) el 04/11/2019 22:25:46
Hola tengo un problema en la línea 61 cargo un txt llamado personas a una tabla, pero me gustaría cargar cualquier archivo txt sin importar el nombre a la tabla ¿Que tendría que hacer?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
package proyecto.pkg2do.complejo.turístico;
 
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;
 
 
public class Encargado extends javax.swing.JFrame {
    String barra= File.separator;//esto es la barra invertida es para que no de error en linux
    String ubicacionBD = System.getProperty("user.dir")+barra+"Registros"+barra;// User.dir es para ubicar los archivos dentro de la carpeta del programa
  private ArrayList<persona> Lis;
 
  public Encargado() {
        Lis = new ArrayList<persona>();
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        setTitle("Encargado");
        cargardatos();
    }
 
    private void limpiar(){
    txtCI.setText("");
    txtNombre.setText("");
    txtApellido.setText("");
    txtAire.setText("");
    txtParrillero.setText("");
    txtCod.setText("");
    txtCantCam.setText("");
    TxtCantH.setText("");
    }
 
    private void verDatosEnTabla(){
        String Mat[][] = new String [Lis.size()][8];
        persona aux;
        for (int i = 0; i < Lis.size(); i++) {
            aux = Lis.get(i);
            Mat[i][0] = aux.getNombre();
            Mat[i][1] = aux.getApellido();
            Mat[i][2] = Long.toString(aux.getCI());
            Mat[i][3] = Integer.toString(aux.getCantidadDeHab());
            Mat[i][4] = Integer.toString(aux.getCantidadDeCam());
            Mat[i][5] = aux.getParrillero();
            Mat[i][6] = aux.getAire();
            Mat[i][7] = aux.getCodigo();
 
            tablaPersonas.setModel(new javax.swing.table.DefaultTableModel(
                Mat,
                new String [] {
                    "Nombre", "Apellido", "CI", "Cant Habitaciones", "Cant Camas", "Parrillero", "Aire acondicionado", "Codigo"
                }
            ));
        }
    }
    public void cargardatos(){
        File Archivo = new File(ubicacionBD+"personas.txt");
        FileReader Leer;
        BufferedReader Almacen;
        persona per, aux = new persona();
        try {
            Leer= new FileReader(Archivo);
            Almacen = new BufferedReader(Leer);
            per = aux.cargar(Almacen);
            while (per != null) {
                Lis.add(per);
                per = aux.cargar(Almacen);
            }
            Almacen.close();
            Leer.close();
        } catch (Exception e) {
        }
         verDatosEnTabla();
    }
 public void cod(){
 
        Random rnd=new Random();
        String abecedario="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String cadena="";
        int m=0,pos=0,num;
        while(m<1){
            pos=(int)(rnd.nextDouble() * abecedario.length()-1 + 0);
            num=(int)(rnd.nextDouble() * 9999 + 1000);
            cadena=cadena+abecedario.charAt(pos)+num;
            pos=(int)(rnd.nextDouble() * abecedario.length()-1 + 0);
            cadena=cadena+abecedario.charAt(pos);
 
            txtCod.setText(cadena);
 
        cadena="";
        m++;
        }
    }
 
    private void guardar(){
        String archivo = "personas.txt";
        File file = new File(ubicacionBD+archivo);
        PrintWriter Escribe;
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (Exception e) {
            }
        }
        try {
            persona aux;
            Escribe = new PrintWriter(file, "utf-8"/*esto es para que se escriba y conserve los datos dentro del archivo*/);
            for (int i = 0; i < Lis.size(); i++) {
                aux=Lis.get(i);
                aux.guardar(Escribe);
            }
            Escribe.close();
        } catch (Exception e) {
        }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        modificar = new javax.swing.JButton();
        agregar = new javax.swing.JButton();
        eliminar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaPersonas = new javax.swing.JTable();
        txtNombre = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtApellido = new javax.swing.JTextField();
        txtCI = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        TxtCantH = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtCantCam = new javax.swing.JTextField();
        txtParrillero = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtAire = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtCod = new javax.swing.JTextField();
        GENERAR = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
 
        modificar.setText("Modificar");
        modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarActionPerformed(evt);
            }
        });
 
        agregar.setText("Agregar");
        agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarActionPerformed(evt);
            }
        });
 
        eliminar.setText("Eliminar");
        eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminarActionPerformed(evt);
            }
        });
 
        tablaPersonas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
 
            },
            new String [] {
                "Nombre", "Apellido", "CI", "Cant Habitaciones", "Cant Camas", "Parrillero", "Aire acondicionado", "Código"
            }
        ));
        jScrollPane1.setViewportView(tablaPersonas);
 
        txtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombreActionPerformed(evt);
            }
        });
 
        jLabel1.setText("Nombre");
 
        jLabel2.setText("Apellido");
 
        txtApellido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtApellidoActionPerformed(evt);
            }
        });
 
        txtCI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCIActionPerformed(evt);
            }
        });
 
        jLabel3.setText("CI");
 
        jLabel4.setText("Cant Hab");
 
        TxtCantH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtCantHActionPerformed(evt);
            }
        });
 
        jLabel5.setText("Cant Cam");
 
        txtCantCam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCantCamActionPerformed(evt);
            }
        });
 
        txtParrillero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtParrilleroActionPerformed(evt);
            }
        });
 
        jLabel6.setText("Parrille");
 
        jLabel7.setText("Aire acon");
 
        txtAire.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAireActionPerformed(evt);
            }
        });
 
        jLabel8.setText("Código");
 
        txtCod.setEditable(false);
        txtCod.setFont(new java.awt.Font("Latha", 0, 11)); // NOI18N
        txtCod.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodActionPerformed(evt);
            }
        });
 
        GENERAR.setText("GENERAR");
        GENERAR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GENERARActionPerformed(evt);
            }
        });
 
        jLabel9.setText("Nombre");
 
        txtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBuscarActionPerformed(evt);
            }
        });
 
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtCI, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(TxtCantH, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtCantCam, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtParrillero, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtAire, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtCod, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(GENERAR))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBuscar)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(eliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(agregar)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)
                            .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(txtCI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(TxtCantH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(txtCantCam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(txtParrillero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(txtAire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(GENERAR)))
                    .addComponent(txtCod))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(modificar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)
                            .addComponent(btnBuscar))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(eliminar)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void txtApellidoActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void txtCIActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void TxtCantHActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void txtCantCamActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void txtParrilleroActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void txtAireActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void agregarActionPerformed(java.awt.event.ActionEvent evt) {
        String nom,ape,parrille,aire,codigo;
        int cantHab,cantCam;
        long ci;
        try {
            nom = txtNombre.getText();
            ape = txtApellido.getText();
            parrille = txtParrillero.getText();
            aire = txtAire.getText();
            codigo = txtCod.getText();
            ci = Long.parseLong(txtCI.getText());
            cantHab= Integer.parseInt(TxtCantH.getText());
            cantCam= Integer.parseInt(TxtCantH.getText());
                if(txtParrillero.getText().equals("si") ){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("Si")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("SI")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("sI")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("no")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("No")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("NO")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else if(txtParrillero.getText().equals("nO")){
                                Lis.add(new persona( nom , ape,ci , cantHab, cantCam, parrille, aire, codigo ));
                }else{
                    JOptionPane.showMessageDialog(null, "Error verifica los datos");
                }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Verifica los datos");
        }
        verDatosEnTabla();
        limpiar();
 
    }
 
    private void txtCodActionPerformed(java.awt.event.ActionEvent evt) {
 
    }
 
    private void GENERARActionPerformed(java.awt.event.ActionEvent evt) {
        cod();
    }
 
    private void eliminarActionPerformed(java.awt.event.ActionEvent evt) {
        int c;
        try {
            c =tablaPersonas.getSelectedRow();
            Lis.remove(c);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Por favor elija una fila");
        }
        verDatosEnTabla();
    }
 
    private void modificarActionPerformed(java.awt.event.ActionEvent evt) {
      int c,CantH, CantC;
      String nombre, apellido, codigo,parrillero,aire;
      long ci;
      persona aux, auxc, auxd, auxb, auxf, auxs, auxu, auxi;
 
        try {
                c = tablaPersonas.getSelectedRow();
            auxd = Lis.get(c);
 
            nombre = JOptionPane.showInputDialog("Nuevo nombre");
            auxd.setNombre(nombre);
 
             c = tablaPersonas.getSelectedRow();
            auxb = Lis.get(c);
 
            apellido = JOptionPane.showInputDialog("Nuevo apellido");
            auxb.setApellido(apellido);
 
            c = tablaPersonas.getSelectedRow();
            auxf = Lis.get(c);
 
            ci = Long.parseLong(JOptionPane.showInputDialog("Nueva CI"));
            auxf.setCI(ci);
 
            c = tablaPersonas.getSelectedRow();
            aux = Lis.get(c);
 
            CantH = Integer.parseInt(JOptionPane.showInputDialog("Nueva cantidad de habitaciones"));
            aux.setCantidadDeHab(CantH);
 
            c = tablaPersonas.getSelectedRow();
            auxc = Lis.get(c);
 
            CantC = Integer.parseInt(JOptionPane.showInputDialog("Nueva cantidad de camas"));
            auxc.setCantidadDeCam(CantC);
 
            c = tablaPersonas.getSelectedRow();
            auxs = Lis.get(c);
 
            parrillero = JOptionPane.showInputDialog("¿Desea parrillero?");
            auxs.setParrillero(parrillero);
 
            c = tablaPersonas.getSelectedRow();
            auxu = Lis.get(c);
 
            aire = JOptionPane.showInputDialog("¿Desea aire acondicionado?");
            auxu.setAire(aire);
 
            c = tablaPersonas.getSelectedRow();
            auxi = Lis.get(c);
 
            codigo = JOptionPane.showInputDialog("Nuevo código");
            auxi.setCodigo(codigo);
 
 
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, "Escoje una fila");
        }
        verDatosEnTabla();
    }
 
    private void formWindowClosing(java.awt.event.WindowEvent evt) {
       String botones[] = {"Si", "No"};
             int n = JOptionPane.showOptionDialog(null, "¿Desea guardar la información?", "Titulo", 0,0, null, botones, null);
             if(n == 0)
                 guardar();
    }
 
    private void txtBuscarActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {
      if(!txtBuscar.getText().isEmpty()){
 
      }else{
          JOptionPane.showMessageDialog(null, "Ingrese datos");
      }
    }
 
    /**
     * @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(Encargado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Encargado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Encargado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Encargado.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 Encargado().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton GENERAR;
    private javax.swing.JTextField TxtCantH;
    private javax.swing.JButton agregar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton eliminar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton modificar;
    private javax.swing.JTable tablaPersonas;
    private javax.swing.JTextField txtAire;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtCI;
    private javax.swing.JTextField txtCantCam;
    public static javax.swing.JTextField txtCod;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtParrillero;
    // End of variables declaration                   
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Billy Joel
Val: 2.665
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problema con un txt en Java

Publicado por Billy Joel (876 intervenciones) el 04/11/2019 23:04:52
Podrías utilizar un JFileChooser

Acá te dejo un ejemplo de como podrías utilizarlo...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFileChooser;
 
public class Main {
 
    public static void main(String[] args) {
        JFileChooser fileChooser = new JFileChooser();
        int seleccion = fileChooser.showOpenDialog(null);
        if (seleccion == JFileChooser.APPROVE_OPTION) {
            File fichero = fileChooser.getSelectedFile();
            leer(fichero);
        }
    }
 
    public static void leer(File archivo) {
        FileReader fr = null;
        BufferedReader br;
        try {
            fr = new FileReader(archivo);
            br = new BufferedReader(fr);
            String linea;
            while ((linea = br.readLine()) != null) {
                System.out.println(linea);
            }
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally {
            try {
                if (null != fr) {
                    fr.close();
                }
            } catch (IOException e2) {
                e2.printStackTrace(System.out);
            }
        }
    }
}

Saludos,
Billy Joel
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con un txt en Java

Publicado por Renzo (232 intervenciones) el 04/11/2019 23:13:20
Hola
en lugar de referenciar a un archivo, puedes referenciar a una carpeta, que también es un File.
Luego, haciendo uso del método getFiles, puedes identificar los archivos contenidos en dicha carpeta y cargarlos.

1
2
3
4
5
6
7
8
File folder = new File("/Users/you/folder/");
File[] listOfFiles = folder.listFiles();
 
for (File file : listOfFiles) {
    if (file.isFile()) {
        System.out.println(file.getName());
    }
}

Saludos

Renzo

http://www.imagineanddo.com/search/label/java
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar