Netbeans - AYUDA CON CODIGO EN NETBEANS

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

AYUDA CON CODIGO EN NETBEANS

Publicado por alexis (1 intervención) el 25/06/2021 16:33:32
ALGUIEN ME PUEDE AYUDAR CON ESTE ERROR ?

ESTE ES EL CODIGO

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
package Formularios;
 
import Datos.DAlmacen;
import Datos.DDetalleFacturas;
import Datos.DFactura;
import Logica.LAlmacen;
import Logica.LDetalleFacturas;
import Logica.LFactura;
import java.awt.event.KeyEvent;
import java.sql.Date;
import java.text.DecimalFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
 
/**
 *
 */
public final class FrmFacturas extends javax.swing.JInternalFrame {
 
    DefaultTableModel miModelo;
    static int idlineas = 0;
 
    public static void setProveedores(String id, String proveedor) {
        txtIdProveedores.setText(id);
        txtProveedor.setText(proveedor);
    }
 
    public static void setLinea(String id, String linea) {
        idlineas = Integer.parseInt(id);
        txtIdLineas.setText(id);
        txtLinea.setText(linea);
    }
 
    /**
     * Creates new form FrmFacturas
     */
    public FrmFacturas() {
        initComponents();
        habilitar(true);
        jLabel1.setVisible(false);
        txtIdFacturas.setVisible(false);
        txtIdLineas.setVisible(false);
        txtIdProveedores.setVisible(false);
        txtTotal.setEditable(false);
        miModelo = (DefaultTableModel) tblFacturas.getModel();
 
        tblFacturas.getColumn("CODIGO").setWidth(15);
        tblFacturas.getColumn("CODIGO").setPreferredWidth(15);
 
        tblFacturas.getColumn("DESCRIPCION").setWidth(220);
        tblFacturas.getColumn("DESCRIPCION").setPreferredWidth(220);
 
        tblFacturas.getColumn("CANTIDAD").setWidth(20);
        tblFacturas.getColumn("CANTIDAD").setPreferredWidth(20);
 
        tblFacturas.getColumn("U/MEDIDA").setWidth(20);
        tblFacturas.getColumn("U/MEDIDA").setPreferredWidth(20);
 
        tblFacturas.getColumn("P/UNITARIO").setWidth(20);
        tblFacturas.getColumn("P/UNITARIO").setPreferredWidth(20);
 
        tblFacturas.getColumn("TOTAL").setWidth(20);
        tblFacturas.getColumn("TOTAL").setPreferredWidth(20);
 
        txtIdLineas.setEnabled(false);
        txtIdProveedores.setEnabled(false);
 
    }
 
    public void habilitar(boolean b) {
        txtEnter.setEnabled(!b);
        txtFecha.setEnabled(!b);
        txtLinea.setEnabled(!b);
        txtProveedor.setEnabled(!b);
        btnCancelar.setEnabled(!b);
        btnGuardar.setEnabled(!b);
        btnBuscarLinea.setEnabled(!b);
        btnBuscarProveedor.setEnabled(!b);
        btnNuevo.setEnabled(b);
 
    }
 
    /**
     * 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() {
 
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtIdFacturas = new javax.swing.JTextField();
        txtLinea = new javax.swing.JTextField();
        txtProveedor = new javax.swing.JTextField();
        btnBuscarLinea = new javax.swing.JButton();
        btnBuscarProveedor = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblFacturas = new javax.swing.JTable();
        btnNuevo = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        txtIdLineas = new javax.swing.JTextField();
        txtIdProveedores = new javax.swing.JTextField();
        txtFecha = new com.toedter.calendar.JDateChooser();
        txtEnter = new javax.swing.JTextField();
        txtTotal = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
 
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setPreferredSize(new java.awt.Dimension(750, 530));
 
        jPanel1.setBackground(new java.awt.Color(153, 153, 255));
 
        jLabel1.setText("ID:");
 
        jLabel2.setText("LINEA:");
 
        jLabel3.setText("PROVEEDOR:");
 
        jLabel4.setText("FECHA:");
 
        btnBuscarLinea.setText("...");
        btnBuscarLinea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarLineaActionPerformed(evt);
            }
        });
 
        btnBuscarProveedor.setText("...");
        btnBuscarProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarProveedorActionPerformed(evt);
            }
        });
 
        tblFacturas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
 
            },
            new String [] {
                "CODIGO", "DESCRIPCION", "CANTIDAD", "U/MEDIDA", "P/UNITARIO", "TOTAL"
            }
        ));
        tblFacturas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tblFacturasKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tblFacturas);
 
        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Nuevo.png"))); // NOI18N
        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
 
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Guardar.jpg"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
 
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
 
        txtEnter.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtEnter.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEnterKeyPressed(evt);
            }
        });
 
        txtTotal.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTotalActionPerformed(evt);
            }
        });
 
        jLabel5.setText("TOTAL:");
 
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtProveedor, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtIdFacturas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLinea, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnBuscarLinea, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscarProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtIdLineas)
                            .addComponent(txtIdProveedores, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 717, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(txtIdFacturas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(txtLinea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscarLinea)
                    .addComponent(txtIdLineas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel3)
                    .addComponent(txtProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscarProveedor)
                    .addComponent(txtIdProveedores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(32, 32, 32)
                .addComponent(txtEnter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>
 
    private void btnBuscarLineaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        FrmBuscarLineas mi = new FrmBuscarLineas(new JFrame(), true);
        mi.setLocationRelativeTo(null);
        mi.setVisible(true);
 
    }
 
    private void btnBuscarProveedorActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        FrmBuscarProveedores mi = new FrmBuscarProveedores(new JFrame(), true);
        mi.setLocationRelativeTo(null);
        mi.setVisible(true);
    }
 
    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        habilitar(false);
    }
 
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        String msg = "", msgfinal = "";
        if (txtLinea.getText().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Campo linea obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            txtLinea.requestFocusInWindow();
            return;
        }
        if (txtProveedor.getText().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Campo proveedor obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            txtProveedor.requestFocusInWindow();
            return;
        }
        if (txtFecha.getDate() == null) {
            JOptionPane.showMessageDialog(rootPane, "Campo fecha obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            txtFecha.requestFocusInWindow();
            return;
        }
 
        LFactura fn = new LFactura();
        DFactura dts = new DFactura();
        dts.setLineasId(Integer.parseInt(txtIdLineas.getText()));
 
        dts.setProveedoresId(Integer.parseInt(txtIdProveedores.getText()));
 
        Calendar cal;
 
        cal = txtFecha.getCalendar();
 
        int aa, mm, dd;
 
        aa = cal.get(Calendar.YEAR) - 1900;
        mm = cal.get(Calendar.MONTH);
        dd = cal.get(Calendar.DAY_OF_MONTH);
 
        dts.setFechaEntrada(new Date(aa, mm, dd));
        txtProveedor.setText("");
        txtLinea.setText("");
        txtLinea.setEnabled(false);
        txtProveedor.setEnabled(false);
        int idfact = fn.insertarFacturas(dts);
 
        if (idfact > 0) {
            int filas = tblFacturas.getRowCount();
            for (int i = 0; i < filas; i++) {
                String idprod = tblFacturas.getValueAt(i, 0).toString();
                String descrip = tblFacturas.getValueAt(i, 1).toString();
                int cantidad = Integer.parseInt(tblFacturas.getValueAt(i, 2).toString());
                String umedida = tblFacturas.getValueAt(i, 3).toString();
                double punitario = Double.parseDouble(tblFacturas.getValueAt(i, 4).toString());
                double total = Double.parseDouble(tblFacturas.getValueAt(i, 5).toString());
 
                LDetalleFacturas fundf = new LDetalleFacturas();
                DDetalleFacturas dtsf = new DDetalleFacturas();
                dtsf.setFacturasId(idfact);
                dtsf.setProductosId(idprod);
                dtsf.setCantidad(cantidad);
                dtsf.setTotal(total);
 
                String mensaje = fundf.registrarDetalleFactura(dtsf);
 
                if (mensaje.equals("si")) {
                    LAlmacen funAl = new LAlmacen();
                    DAlmacen dtsp = new DAlmacen();
 
                    dtsp.setIdAlmacen(idprod);
                    dtsp.setDescripcion(descrip);
                    dtsp.setStock(cantidad);
                    dtsp.setUMedida(umedida);
                    dtsp.setPUnitario(punitario);
                    dtsp.setLineasId(idlineas);
 
                    msgfinal = funAl.insertarProductos(dtsp);
 
                }
 
            }
            JOptionPane.showMessageDialog(rootPane, msgfinal, "Información", JOptionPane.INFORMATION_MESSAGE);
 
        } else {
            JOptionPane.showMessageDialog(rootPane, "Ocurio un problema al insertar", "Información", JOptionPane.ERROR_MESSAGE);
        }
        limpiar();
        habilitar(true);
 
 
    }
    public void limpiar() {
        txtLinea.setText("m");
        txtEnter.setText("");
        txtFecha.setDate(null);
        txtProveedor.setText("m");
        txtIdFacturas.setText("");
        txtIdLineas.setText("");
        txtIdProveedores.setText("");
        txtTotal.setText("");
        try {
            DefaultTableModel modelo = (DefaultTableModel) tblFacturas.getModel();
            int filas = tblFacturas.getRowCount();
            for (int i = 0; filas > i; i++) {
                modelo.removeRow(0);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al limpiar la tabla.");
        }
    }
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        habilitar(true);
    }
 
    public boolean estaenTabla(String texto) {
        boolean res = false;
        DecimalFormat ft = new DecimalFormat("####.00");
        for (int i = 0; i < tblFacturas.getRowCount(); i++) {
            String codigo = tblFacturas.getValueAt(i, 0).toString();
            if (codigo.equals(texto)) {
                int cantidad = Integer.parseInt(tblFacturas.getValueAt(i, 2).toString());
                double preciounitario = Double.parseDouble(tblFacturas.getValueAt(i, 4).toString());
                int totalcantidad = cantidad + 1;
                tblFacturas.setValueAt(totalcantidad, i, 2);
 
                double totalparcial = totalcantidad * preciounitario;
                tblFacturas.setValueAt(ft.format(totalparcial), i, 5);
                res = true;
            }
        }
        sumarTotal();
        return res;
    }
 
    public void sumarTotal() {
        DecimalFormat ft = new DecimalFormat("####.00");
        double totalparcial = 0, totalfinal = 0;
        for (int i = 0; i < tblFacturas.getRowCount(); i++) {
            totalparcial = Double.parseDouble(tblFacturas.getValueAt(i, 5).toString());
            totalfinal += totalparcial;
            txtTotal.setText(ft.format(totalfinal));
        }
 
    }
    private void txtEnterKeyPressed(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            boolean b = estaenTabla(txtEnter.getText());
            if (b == false) {
                mostrarProductos(txtEnter.getText());
            }
            sumarTotal();
            txtEnter.setText("");
        }
 
 
    }
 
    private void tblFacturasKeyPressed(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
        DecimalFormat ft = new DecimalFormat("####.00");
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            for (int i = 0; i < tblFacturas.getRowCount(); i++) {
                int cantidad = Integer.parseInt(tblFacturas.getValueAt(i, 2).toString());
                double preciounitario = Double.parseDouble(tblFacturas.getValueAt(i, 4).toString());
 
                double totalparcial = cantidad * preciounitario;
                tblFacturas.setValueAt(ft.format(totalparcial), i, 5);
            }
            sumarTotal();
        }
    }
 
    private void txtTotalActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    public void mostrarProductos(String producto) {
        LAlmacen fn = new LAlmacen();
        DAlmacen dts = new DAlmacen();
        DefaultTableModel tblDatos = (DefaultTableModel) tblFacturas.getModel();
        dts.setIdAlmacen(producto);
        String registros[] = fn.mostrarbuscarProductos(dts);
        if (registros[0] != null) {
            tblDatos.insertRow(0, registros);
            tblFacturas.setModel(tblDatos);
        } else {
            registros[0] = txtEnter.getText();
            registros[1] = "";
            registros[2] = "1";
            registros[3] = "";
            registros[4] = "0.00";
            registros[5] = "0.00";
            tblDatos.insertRow(0, registros);
            tblFacturas.setModel(tblDatos);
        }
 
    }
 
    // Variables declaration - do not modify
    private javax.swing.JButton btnBuscarLinea;
    private javax.swing.JButton btnBuscarProveedor;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnNuevo;
    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.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblFacturas;
    private javax.swing.JTextField txtEnter;
    private com.toedter.calendar.JDateChooser txtFecha;
    private javax.swing.JTextField txtIdFacturas;
    public static javax.swing.JTextField txtIdLineas;
    public static javax.swing.JTextField txtIdProveedores;
    public static javax.swing.JTextField txtLinea;
    public static javax.swing.JTextField txtProveedor;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration
 
}

errorjava
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 Kabuto
Val: 12
Ha aumentado su posición en 13 puestos en Netbeans (en relación al último mes)
Gráfica de Netbeans

AYUDA CON CODIGO EN NETBEANS

Publicado por Kabuto (17 intervenciones) el 27/06/2021 00:28:04
Hola.

Parece que el problema es que en este método:

1
2
3
4
5
6
7
8
public void sumarTotal() {
    DecimalFormat ft = new DecimalFormat("####.00");
    double totalparcial = 0, totalfinal = 0;
    for (int i = 0; i < tblFacturas.getRowCount(); i++) {
        totalparcial = Double.parseDouble(tblFacturas.getValueAt(i, 5).toString());
        totalfinal += totalparcial;
        txtTotal.setText(ft.format(totalfinal));
    }

Falla al parsear a Double porque el importe que recibes de la tabla facturas llega con "coma decimal".
1
"50,00"
Pero el parseador solo sabe parsear valores con "punto decimal"
1
"50.00"

Este problema es habitual en paises de habla hispana. Normalmente usamos la coma decimal, al contrario que en países anglosajones que usan punto decimal.

Entonces el sistema intenta adaptarse a nuestra localización y nos muestra los valores con coma decimal, pero luego al recuperar ese valor, muchas funciones internas no están preparadas para trabajar con esa coma decimal y se lía este kilombo.

Una forma fácil de evitarlo es usando el método replace() de la clase String, para indicarle que "reemplace" la coma por un punto.

1
2
3
4
5
6
7
8
9
10
public void sumarTotal() {
    DecimalFormat ft = new DecimalFormat("####.00");
    double totalparcial = 0, totalfinal = 0;
    for (int i = 0; i < tblFacturas.getRowCount(); i++) {
        String valor = tblFacturas.getValueAt(i, 5).toString(); //Recuperamos valor
        valor = valor.replace("," , "."); //Sustituimos coma por punto
        totalparcial = Double.parseDouble(valor); //Parseamos
        totalfinal += totalparcial;
        txtTotal.setText(ft.format(totalfinal));
    }
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