Java - Problemas al guardar datos del objeto

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

Problemas al guardar datos del objeto

Publicado por Daniel (19 intervenciones) el 19/06/2019 19:59:00
Hola, estaba arreglando un prollecto para agregarle una intefaz visual hecha en el Net Beans y me da problemas cuando le doy guardar en las lineas

jue.insertar_Jugador_de_Campo(nombrec.getText(), paisc.getText(), deporte.getText(), getResultado(), b)
jue.insertar_pesista(nombre.getText(), pais.getText(), c, d, e, f, a);

;que es donde guardo las propiedades de los objetos Pesista y Deportista de campo
Por favor ayudenme
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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Interfaz_Proyecto extends javax.swing.JFrame {
 
    /**
     * Creates new form
     */
    private Juegos_Deportivos jue;
    private int a = 0;
    private int b = 0;
    float[] resultado;
 
    public Interfaz_Proyecto() {
        initComponents();
        //int z = Integer.parseInt(cantpas.getText());
        //int w = Integer.parseInt(cantcamp.getText());
        int z=3;
        int w=3;
        Juegos_Deportivos jue = new Juegos_Deportivos(z, w);
    }
 
    /**
     * 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() {
 
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cantpas = new javax.swing.JTextField();
        cantcamp = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        pais = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        peso = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        envion = new javax.swing.JTextField();
        palanqueta = new javax.swing.JTextField();
        arranque = new javax.swing.JTextField();
        Guardar_datos_pesista = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        nombrec = new javax.swing.JTextField();
        paisc = new javax.swing.JTextField();
        deporte = new javax.swing.JTextField();
        intentos = new javax.swing.JTextField();
        resultados = new javax.swing.JTextField();
        Guardar_datos_deportista = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        nomgan = new javax.swing.JTextField();
        mostrarnomgan = new javax.swing.JButton();
        labnomgan = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        nomresfin = new javax.swing.JTextField();
        mostrarresfin = new javax.swing.JButton();
        labresfin = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        marca = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        pesosup = new javax.swing.JTextField();
        mostrarrequisito = new javax.swing.JButton();
        jLabel20 = new javax.swing.JLabel();
        labreq = new javax.swing.JLabel();
        Guardar_resultados = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jLabel1.setText("Cantidad de deportistas de campo");
 
        jLabel2.setText("Cantidad de pesistas");
 
        cantpas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantpasActionPerformed(evt);
            }
        });
 
        jLabel3.setText("Nombre del pesista");
 
        jLabel4.setText("País que representa");
 
        jLabel5.setText("Peso");
 
        peso.setText("0");
        peso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesoActionPerformed(evt);
            }
        });
 
        jLabel6.setText("Resultado envion");
 
        jLabel7.setText("Resultado Palanqueta");
 
        jLabel8.setText("Resultado Arranque");
 
        envion.setText("0");
        envion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                envionActionPerformed(evt);
            }
        });
 
        palanqueta.setText("0");
 
        arranque.setText("0");
        arranque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arranqueActionPerformed(evt);
            }
        });
 
        Guardar_datos_pesista.setText("Guardar");
        Guardar_datos_pesista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_pesistaActionPerformed(evt);
            }
        });
 
        jLabel9.setText("Nombre");
 
        jLabel10.setText("País");
 
        jLabel11.setText("Deporte");
 
        jLabel12.setText("Intentos");
 
        jLabel13.setText("Resultados");
 
        nombrec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombrecActionPerformed(evt);
            }
        });
 
        paisc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paiscActionPerformed(evt);
            }
        });
 
        intentos.setText("0");
 
        resultados.setText("0");
        resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resultadosActionPerformed(evt);
            }
        });
 
        Guardar_datos_deportista.setText("Guardar");
        Guardar_datos_deportista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_deportistaActionPerformed(evt);
            }
        });
 
        jLabel14.setText("Inserte nombre del deporte de campo para conocer su ganador");
 
        mostrarnomgan.setText("Mostrar");
        mostrarnomgan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarnomganActionPerformed(evt);
            }
        });
 
        labnomgan.setText("...");
 
        jLabel16.setText("Inserte el nombre de un deportista par saber su resultado final");
 
        nomresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomresfinActionPerformed(evt);
            }
        });
 
        mostrarresfin.setText("Mostrar");
        mostrarresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarresfinActionPerformed(evt);
            }
        });
 
        labresfin.setText("...");
 
        jLabel18.setText("Establesca la marca a superar por los pesistas");
 
        marca.setText("0");
        marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                marcaActionPerformed(evt);
            }
        });
 
        jLabel19.setText("Establesca en que peso se debe comprovar");
 
        pesosup.setText("0");
 
        mostrarrequisito.setText("Mostrar");
        mostrarrequisito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarrequisitoActionPerformed(evt);
            }
        });
 
        jLabel20.setText("Quien cumplio con el requisito fue:");
 
        labreq.setText("...");
 
        Guardar_resultados.setText("Guardar resultados");
        Guardar_resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_resultadosActionPerformed(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()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(mostrarrequisito)
                        .addGap(37, 37, 37)
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labreq))
                    .addComponent(jLabel16)
                    .addComponent(jLabel14)
                    .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_datos_deportista)
                    .addComponent(jLabel2)
                    .addComponent(Guardar_datos_pesista)
                    .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(nombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4)
                            .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(envion))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(55, 55, 55)
                                .addComponent(jLabel10)
                                .addGap(61, 61, 61)
                                .addComponent(jLabel11)
                                .addGap(173, 173, 173)
                                .addComponent(jLabel13)))
                        .addGap(18, 18, 18)
                        .addComponent(Guardar_resultados))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(mostrarnomgan)
                        .addGap(31, 31, 31)
                        .addComponent(labnomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(mostrarresfin)
                        .addGap(36, 36, 36)
                        .addComponent(labresfin))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(envion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(Guardar_datos_pesista)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_resultados))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Guardar_datos_deportista)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarnomgan)
                    .addComponent(labnomgan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarresfin)
                    .addComponent(labresfin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(mostrarrequisito))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel20)
                        .addComponent(labreq)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void cantpasActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void envionActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void arranqueActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void nombrecActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void paiscActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarnomganActionPerformed(java.awt.event.ActionEvent evt) {
 
        labnomgan.setText(jue.Ganador_de_Campo(nomgan.getText()));
    }
 
    private void nomresfinActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarresfinActionPerformed(java.awt.event.ActionEvent evt) {
 
        float asd=jue.Mayor_Resultado_de_Jugadores(nomresfin.getText());
        labresfin.setText(""+asd);
 
    }
 
    private void marcaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void Guardar_datos_pesistaActionPerformed(java.awt.event.ActionEvent evt) {
 
        int c = Integer.parseInt(peso.getText());
        int d = Integer.parseInt(envion.getText());
        int e = Integer.parseInt(palanqueta.getText());
        int f = Integer.parseInt(arranque.getText());
        System.out.println(nombre.getText()+""+ pais.getText()+""+ c+""+""+""+ d+""+ e+""+ f+"" +a);
        jue.insertar_pesista(nombre.getText(), pais.getText(), c, d, e, f, a);
        a++;
    }
 
    private void Guardar_datos_deportistaActionPerformed(java.awt.event.ActionEvent evt) {
 
 
        jue.insertar_Jugador_de_Campo(nombrec.getText(), paisc.getText(), deporte.getText(), getResultado(), b);
        b++;
    }
 
    private void Guardar_resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        int x = Integer.parseInt(intentos.getText());
        float resultado[] = new float[x];
        for (int i = 0; i < x; i++) {
            int y = Integer.parseInt(resultados.getText());
            resultado[i] = y;
        }
        setResultados(resultado);
    }
 
    private void mostrarrequisitoActionPerformed(java.awt.event.ActionEvent evt) {
 
        float g= Integer.parseInt(marca.getText());
        float h = Integer.parseInt(pesosup.getText());
        labreq.setText(jue.Mayor_que_Marca(h, g));
    }
 
    private void pesoActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    /**
     * @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(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.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 Interfaz_Proyecto().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton Guardar_datos_deportista;
    private javax.swing.JButton Guardar_datos_pesista;
    private javax.swing.JButton Guardar_resultados;
    private javax.swing.JTextField arranque;
    private javax.swing.JTextField cantcamp;
    private javax.swing.JTextField cantpas;
    private javax.swing.JTextField deporte;
    private javax.swing.JTextField envion;
    private javax.swing.JTextField intentos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    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.JLabel labnomgan;
    private javax.swing.JLabel labreq;
    private javax.swing.JLabel labresfin;
    private javax.swing.JTextField marca;
    private javax.swing.JButton mostrarnomgan;
    private javax.swing.JButton mostrarrequisito;
    private javax.swing.JButton mostrarresfin;
    private javax.swing.JTextField nombre;
    private javax.swing.JTextField nombrec;
    private javax.swing.JTextField nomgan;
    private javax.swing.JTextField nomresfin;
    private javax.swing.JTextField pais;
    private javax.swing.JTextField paisc;
    private javax.swing.JTextField palanqueta;
    private javax.swing.JTextField peso;
    private javax.swing.JTextField pesosup;
    private javax.swing.JTextField resultados;
    // End of variables declaration                   
 
    private void setResultados(float[] resultado) {
        this.resultado=resultado;
    }
 
    public float[] getResultado() {
        return resultado;
    }
}
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 Rodrigo
Val: 2.041
Plata
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Rodrigo (623 intervenciones) el 19/06/2019 20:14:06
2 Sugerencias:
- Explica mejor lo que ocurre. "Me da problemas" no es la mejor descripcion
- Usa nombres de variables que indiquen que es lo que guardan. Estas usando el abecedario para los nombres de las variables y eso no invita ni ayuda a leerlo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 55
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Daniel (19 intervenciones) el 19/06/2019 20:44:52
muchas gracias por las sugerencias
el problema es cuando se tocan los botones de guardar en los que se deberia de guardar los datos de los objetos
se produse un
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

aqui envio el codigo mejor visto es largo porque esta hecho con las herramientas del Net Beans
nota: antes de ponerle interfas visual al programa no daba errores
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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Interfaz_Proyecto extends javax.swing.JFrame {
 
    /**
     * Creates new form
     */
    private Juegos_Deportivos jue;
    private int a = 0;
    private int b = 0;
    float[] resultado;
 
    public Interfaz_Proyecto() {
        initComponents();
        //int z = Integer.parseInt(cantpas.getText());
        //int w = Integer.parseInt(cantcamp.getText());
        int z=3;
        int w=3;
        Juegos_Deportivos jue = new Juegos_Deportivos(z, w);
    }
 
    /**
     * 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() {
 
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cantpas = new javax.swing.JTextField();
        cantcamp = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        pais = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        peso = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        envion = new javax.swing.JTextField();
        palanqueta = new javax.swing.JTextField();
        arranque = new javax.swing.JTextField();
        Guardar_datos_pesista = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        nombrec = new javax.swing.JTextField();
        paisc = new javax.swing.JTextField();
        deporte = new javax.swing.JTextField();
        intentos = new javax.swing.JTextField();
        resultados = new javax.swing.JTextField();
        Guardar_datos_deportista = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        nomgan = new javax.swing.JTextField();
        mostrarnomgan = new javax.swing.JButton();
        labnomgan = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        nomresfin = new javax.swing.JTextField();
        mostrarresfin = new javax.swing.JButton();
        labresfin = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        marca = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        pesosup = new javax.swing.JTextField();
        mostrarrequisito = new javax.swing.JButton();
        jLabel20 = new javax.swing.JLabel();
        labreq = new javax.swing.JLabel();
        Guardar_resultados = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jLabel1.setText("Cantidad de deportistas de campo");
 
        jLabel2.setText("Cantidad de pesistas");
 
        cantpas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantpasActionPerformed(evt);
            }
        });
 
        jLabel3.setText("Nombre del pesista");
 
        jLabel4.setText("País que representa");
 
        jLabel5.setText("Peso");
 
        peso.setText("0");
        peso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesoActionPerformed(evt);
            }
        });
 
        jLabel6.setText("Resultado envion");
 
        jLabel7.setText("Resultado Palanqueta");
 
        jLabel8.setText("Resultado Arranque");
 
        envion.setText("0");
        envion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                envionActionPerformed(evt);
            }
        });
 
        palanqueta.setText("0");
 
        arranque.setText("0");
        arranque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arranqueActionPerformed(evt);
            }
        });
 
        Guardar_datos_pesista.setText("Guardar");
        Guardar_datos_pesista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_pesistaActionPerformed(evt);
            }
        });
 
        jLabel9.setText("Nombre");
 
        jLabel10.setText("País");
 
        jLabel11.setText("Deporte");
 
        jLabel12.setText("Intentos");
 
        jLabel13.setText("Resultados");
 
        nombrec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombrecActionPerformed(evt);
            }
        });
 
        paisc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paiscActionPerformed(evt);
            }
        });
 
        intentos.setText("0");
 
        resultados.setText("0");
        resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resultadosActionPerformed(evt);
            }
        });
 
        Guardar_datos_deportista.setText("Guardar");
        Guardar_datos_deportista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_deportistaActionPerformed(evt);
            }
        });
 
        jLabel14.setText("Inserte nombre del deporte de campo para conocer su ganador");
 
        mostrarnomgan.setText("Mostrar");
        mostrarnomgan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarnomganActionPerformed(evt);
            }
        });
 
        labnomgan.setText("...");
 
        jLabel16.setText("Inserte el nombre de un deportista par saber su resultado final");
 
        nomresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomresfinActionPerformed(evt);
            }
        });
 
        mostrarresfin.setText("Mostrar");
        mostrarresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarresfinActionPerformed(evt);
            }
        });
 
        labresfin.setText("...");
 
        jLabel18.setText("Establesca la marca a superar por los pesistas");
 
        marca.setText("0");
        marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                marcaActionPerformed(evt);
            }
        });
 
        jLabel19.setText("Establesca en que peso se debe comprovar");
 
        pesosup.setText("0");
 
        mostrarrequisito.setText("Mostrar");
        mostrarrequisito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarrequisitoActionPerformed(evt);
            }
        });
 
        jLabel20.setText("Quien cumplio con el requisito fue:");
 
        labreq.setText("...");
 
        Guardar_resultados.setText("Guardar resultados");
        Guardar_resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_resultadosActionPerformed(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()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(mostrarrequisito)
                        .addGap(37, 37, 37)
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labreq))
                    .addComponent(jLabel16)
                    .addComponent(jLabel14)
                    .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_datos_deportista)
                    .addComponent(jLabel2)
                    .addComponent(Guardar_datos_pesista)
                    .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(nombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4)
                            .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(envion))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(55, 55, 55)
                                .addComponent(jLabel10)
                                .addGap(61, 61, 61)
                                .addComponent(jLabel11)
                                .addGap(173, 173, 173)
                                .addComponent(jLabel13)))
                        .addGap(18, 18, 18)
                        .addComponent(Guardar_resultados))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(mostrarnomgan)
                        .addGap(31, 31, 31)
                        .addComponent(labnomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(mostrarresfin)
                        .addGap(36, 36, 36)
                        .addComponent(labresfin))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(envion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(Guardar_datos_pesista)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_resultados))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Guardar_datos_deportista)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarnomgan)
                    .addComponent(labnomgan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarresfin)
                    .addComponent(labresfin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(mostrarrequisito))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel20)
                        .addComponent(labreq)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void cantpasActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void envionActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void arranqueActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void nombrecActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void paiscActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarnomganActionPerformed(java.awt.event.ActionEvent evt) {
 
        labnomgan.setText(jue.Ganador_de_Campo(nomgan.getText()));
    }
 
    private void nomresfinActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarresfinActionPerformed(java.awt.event.ActionEvent evt) {
 
        float asd=jue.Mayor_Resultado_de_Jugadores(nomresfin.getText());
        labresfin.setText(""+asd);
 
    }
 
    private void marcaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void Guardar_datos_pesistaActionPerformed(java.awt.event.ActionEvent evt) {
 
        int c = Integer.parseInt(peso.getText());
        int d = Integer.parseInt(envion.getText());
        int e = Integer.parseInt(palanqueta.getText());
        int f = Integer.parseInt(arranque.getText());
        System.out.println(nombre.getText()+""+ pais.getText()+""+ c+""+""+""+ d+""+ e+""+ f+"" +a);
        jue.insertar_pesista(nombre.getText(), pais.getText(), c, d, e, f, a);
        a++;
    }
 
    private void Guardar_datos_deportistaActionPerformed(java.awt.event.ActionEvent evt) {
 
 
        jue.insertar_Jugador_de_Campo(nombrec.getText(), paisc.getText(), deporte.getText(), getResultado(), b);
        b++;
    }
 
    private void Guardar_resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        int x = Integer.parseInt(intentos.getText());
        float resultado[] = new float[x];
        for (int i = 0; i < x; i++) {
            int y = Integer.parseInt(resultados.getText());
            resultado[i] = y;
        }
        setResultados(resultado);
    }
 
    private void mostrarrequisitoActionPerformed(java.awt.event.ActionEvent evt) {
 
        float g= Integer.parseInt(marca.getText());
        float h = Integer.parseInt(pesosup.getText());
        labreq.setText(jue.Mayor_que_Marca(h, g));
    }
 
    private void pesoActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    /**
     * @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(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.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 Interfaz_Proyecto().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton Guardar_datos_deportista;
    private javax.swing.JButton Guardar_datos_pesista;
    private javax.swing.JButton Guardar_resultados;
    private javax.swing.JTextField arranque;
    private javax.swing.JTextField cantcamp;
    private javax.swing.JTextField cantpas;
    private javax.swing.JTextField deporte;
    private javax.swing.JTextField envion;
    private javax.swing.JTextField intentos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    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.JLabel labnomgan;
    private javax.swing.JLabel labreq;
    private javax.swing.JLabel labresfin;
    private javax.swing.JTextField marca;
    private javax.swing.JButton mostrarnomgan;
    private javax.swing.JButton mostrarrequisito;
    private javax.swing.JButton mostrarresfin;
    private javax.swing.JTextField nombre;
    private javax.swing.JTextField nombrec;
    private javax.swing.JTextField nomgan;
    private javax.swing.JTextField nomresfin;
    private javax.swing.JTextField pais;
    private javax.swing.JTextField paisc;
    private javax.swing.JTextField palanqueta;
    private javax.swing.JTextField peso;
    private javax.swing.JTextField pesosup;
    private javax.swing.JTextField resultados;
    // End of variables declaration                   
 
    private void setResultados(float[] resultado) {
        this.resultado=resultado;
    }
 
    public float[] getResultado() {
        return resultado;
    }
}
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
Imágen de perfil de Kabuto
Val: 3.428
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Kabuto (1381 intervenciones) el 19/06/2019 21:05:58
Hola,
¿Puedes pasarnos también la clase Juegos_Deportivos y así intentamos ejecutar nosotros tu código?
Quizás viéndo la interfaz en funcionamiento nos podemos hacer una mejor idea de como se supone que debería funcionar y en que momentos se están produciendo los fallos.
Porque leer esto es imposible... a simple vista veo que cuando se recupera los datos de los campos de texto y se parsea a Integer, no se está controlando si los campos estan vacíos, o si lo que hay en los campos no es parseable.
Controlar esto con try catch sería lo ideal. Pero vamos, no se si esto lo que te causa problemas.

Esto de hacer interfaces con el editor de Netbeans, o cualquier otro.... es un horror porque genera de forma automática cientos de líneas de código que luego es inhumano intentar interpretarlas.

No hay nada como diseñar las GUI a mano. Panel a panel, método a método....separandolo en varias clases si hace falta, con tal de que sea legible para un humano.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 55
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Daniel (19 intervenciones) el 19/06/2019 22:33:34
tienes toda la razon yo tampoco lo soporto
aquí estan las demas clases muchas gracias


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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Jugador_de_Campo extends Deportista {
    private String deporte;
    private float [] resultados;
 
    Jugador_de_Campo(String nombre, String pais, String deporte, float[] resultados) {
        this.deporte= deporte;
        this.nombre= nombre;
        this.pais = pais;
        this.resultados=resultados;
 
    }
 
    public String getDeporte() {
        return deporte;
    }
 
    public float[] getResultados() {
        return resultados;
    }
 
    public String getNombre() {
        return nombre;
    }
 
    public String getPais() {
        return pais;
    }
    public float getResultado_Final(){
        float mayor =0;
        for (int i = 0; i < resultados.length; i++) {
            if(mayor<resultados[i]){mayor = resultados[i];
        }
        }return mayor;
    }
 
}

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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Pesista extends Deportista {
    private float peso;
    private float envion;
    private float palanqueta;
    private float arranque;
 
    Pesista(String nombre, String pais, float peso, float envion, float palanqueta, float arranque) {
        this.arranque=arranque;
        this.envion=envion;
        this.palanqueta=palanqueta;
        this.nombre=nombre;
        this.pais=pais;
        this.peso=peso;
    }
 
    public float getPeso() {
        return peso;
    }
 
    public float getEnvion() {
        return envion;
    }
 
    public float getPalanqueta() {
        return palanqueta;
    }
 
    public float getArranque() {
        return arranque;
    }
 
    public String getNombre() {
        return nombre;
    }
 
    public String getPais() {
        return pais;
    }
    public float getResultadofinal(){
        float resultado = arranque+palanqueta+envion;
        return resultado;
    }
}

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
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Juegos_Deportivos {
    private Jugador_de_Campo [] Jugador_de_Campo;
    private Pesista [] Pesista;
 
    public Juegos_Deportivos(int cantpes, int cantcamp) {
       this.Jugador_de_Campo = new Jugador_de_Campo[cantcamp];
       this.Pesista= new Pesista[cantpes];
    }
 
    public void insertar_pesista(String nombre, String pais, float peso, float envion, float palanqueta, float arranque,int pos) {
        Pesista pes=new Pesista(nombre,pais,peso,envion,palanqueta,arranque);
        Pesista[pos]=pes;
    }
 
    public void insertar_Jugador_de_Campo(String nombre, String pais, String deporte, float[] resultados, int pos) {
      Jugador_de_Campo jug = new Jugador_de_Campo(nombre,pais,deporte,resultados);
      Jugador_de_Campo[pos]=jug;
    }
 
    public String Ganador_de_Campo(String deporte){
        String nommay = "Nombre no encontrado";
        float may=0;
        for (int i = 0; i <Jugador_de_Campo.length ; i++) {
            if(Jugador_de_Campo[i].getDeporte().equals(deporte)){
                if(Jugador_de_Campo[i].getResultado_Final()>may){
                    nommay=Jugador_de_Campo[i].getNombre();
                }
 
            }
        }
        return nommay;
    }
    public float Mayor_Resultado_de_Jugadores(String jug){
        float fin=0;
        for (int i = 0; i < Jugador_de_Campo.length; i++) {
            if(Jugador_de_Campo[i].getNombre().equals(jug)){
               Jugador_de_Campo[i].getResultado_Final();
            }
        }
        for (int i = 0; i < Pesista.length; i++) {
            if(Pesista[i].getNombre().equals(jug)){
               Pesista[i].getResultadofinal();
            }
        }
        return fin;
}
 
 
 
    public String Mayor_que_Marca(float pes, float marca) {
        String m="Ningun pesista cumplio con los requisitos";
        for (int i = 0; i <Pesista.length ; i++) {
            if(Pesista[i].getPeso()==pes&&Pesista[i].getResultadofinal()>marca)
 
               m= Pesista[i].getNombre();
        }
 
 
    return m;
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author Daniel Rodriguez
 */
public class Deportista {
    String nombre;
    String pais;
}
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
Imágen de perfil de Kabuto
Val: 3.428
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Kabuto (1381 intervenciones) el 19/06/2019 23:52:45
Ok. Ya veo la interfaz funcionando, aunque no entiendo muy bien el funcionamiento que debería tener.
Por ejemplo el primer campo pregunta por la cantidad de pesistas, pero no creo que sea necesario pedir dicho dato. El número debería depender de las veces que el usuario meta datos (nombre, pais, peso, resultados..) y pulse el botón guardar.
No debería depender de lo que se indique en un campo. No se...


Bueno, da igual. Ya se por qué te está fallando. Es por las dos líneas que te marco en negrita:

1
2
3
4
5
6
7
8
9
10
11
12
13
private Juegos_Deportivos jue;
private int a = 0;
private int b = 0;
float[] resultado;
 
public Interfaz_Proyecto() {
initComponents();
//int z = Integer.parseInt(cantpas.getText());
//int w = Integer.parseInt(cantcamp.getText());
int z=3;
int w=3;
Juegos_Deportivos jue = new Juegos_Deportivos(z, w); //Este objeto es distinto al declarado en los atributos de clase
}

Tu declaras un atributo jue, que es un objeto de la clase Juegos_Deportivos.
OK, eso es correcto.
Luego en el constructor, lo vas a inicializar. Pero al hacerlo, vuelves a poner el nombre de su clase delante del nombre:
1
Juegos_Deportivos jue = new Juegos_Deportivos(z, w);

Esto significa que estás creando un segundo objeto, distinto al del atributo. Aunque se llamen igual, son distintos.

Entonces, el jue que has declarado como atributo, no se está inicializando, se queda con valor null al arrancar el programa.
Y por eso te da el error NullPointerException cuando intentas insertarle datos.

Para corregirlo, simplemente no menciones su clase en el constructor para evitar crear un segundo objeto:

1
2
3
4
5
6
7
8
9
10
11
12
13
private Juegos_Deportivos jue;
private int a = 0;
private int b = 0;
float[] resultado;
 
public Interfaz_Proyecto() {
initComponents();
//int z = Integer.parseInt(cantpas.getText());
//int w = Integer.parseInt(cantcamp.getText());
int z=3;
int w=3;
jue = new Juegos_Deportivos(z, w); //Ahora si estamos inicializando el atributo de clase
}

Con eso ya evitas ese error.

Hay otro botón que falla, el que pide el nombre del deporte de campo para conocer su ganador.... pero no se si es porque no se insertar otros datos previamente de forma correcta.

Además las clases Pesista y JugadorDeCampo no están heredando bien los atributos de Deportista

No se, seguiré mirando el código a ver si lo entiendo mejor
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Kabuto
Val: 3.428
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Kabuto (1381 intervenciones) el 20/06/2019 01:24:59
Ok.
Voy entendiendo mejor de que va esto.
Mira, he hecho algunos cambios correcciones. A ver que te parecen.

La clase Deportista es mejor que tenga sus atributos privados y sus getters y setters propios.
Todo esto lo heredarán sin problemas las siguientes clases.
Yo incluso la he declarado como abstracta, ya que en principio está destinada a ser superclase de otras.
Pero bueno, no es obligatorio hacerlo.

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
public abstract class Deportista {
    private String nombre;
    private String pais;
 
    public Deportista(String nombre, String pais) {
    	this.nombre = nombre;
    	this.pais = pais;
    }
 
	public String getNombre() {
		return nombre;
	}
 
	public void setNombre(String nombre) {
		this.nombre = nombre;
	}
 
	public String getPais() {
		return pais;
	}
 
	public void setPais(String pais) {
		this.pais = pais;
	}
 
}

La siguiente clase, Pesista, no le hecho cambios. Excepto escribir correctamente su constructor para que los atributos nombre y pais sean pasado al constructor de su superclase (Deportista)

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
public class Pesista extends Deportista {
    private float peso;
    private float envion;
    private float palanqueta;
    private float arranque;
 
    public Pesista(String nombre, String pais, float peso, float envion, float palanqueta, float arranque) {
    	super(nombre, pais);
        this.arranque=arranque;
        this.envion=envion;
        this.palanqueta=palanqueta;
        this.peso=peso;
    }
 
    public float getPeso() {
        return peso;
    }
 
    public float getEnvion() {
        return envion;
    }
 
    public float getPalanqueta() {
        return palanqueta;
    }
 
    public float getArranque() {
        return arranque;
    }
 
    public float getResultadofinal(){
        return arranque+palanqueta+envion;
    }
}

Y lo mismo con la clase Jugador_de_Campo, tan solo corregir su constructor:
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
public class Jugador_de_Campo extends Deportista {
    private String deporte;
    private float [] resultados;
 
    public Jugador_de_Campo(String nombre, String pais, String deporte, float[] resultados) {
    	super(nombre, pais);
        this.deporte= deporte;
        this.resultados=resultados;
    }
 
    public String getDeporte() {
        return deporte;
    }
 
    public float[] getResultados() {
        return resultados;
    }
 
    public float getResultado_Final(){
        float mayor =0;
        for (int i = 0; i < resultados.length; i++)
            if(mayor<resultados[i])
            	mayor = resultados[i];
 
        return mayor;
    }
 
}

Pasamos a la clase Juegos_Deportivos. Aquí si que hecho cambios cruciales.

Tú estabas usando arrays primitivos para almacenar los distintos Deportistas. Esto es tremendamente ineficiente, porque los arrays primitivos son estructuras estáticas. Es decir, hay que darles un tamaño fijo y ese tamaño no se puede alterar.
Pero tu no quieres eso. Tú quieres poder arrancar tu programa y añadir tantos Deportistas como te de la gana, sin tener que especificar un valor fijo desde el principio.

Por eso en lugar de usar arrays primitivos, mejor usar algún tipo de colección dinámica. Estas colecciones no tienen tamaño fijo, van creciendo según se le añaden elementos.
Hay muchas para elegir, por ejemplo la clase ArrayList. Yo en este caso, he usado la clase Vector. Pero no por ningún motivo especial. Simplemente, es más que suficiente para lo que necesita este programa.

Al usar este tipo de estructura, verás que cambia la forma de insertar elementos. Siendo mucho más sencillo, ya no tienes que controlar tú manualmente posiciones de indices ni nada.

También he cambiado los métodos que buscan datos. Ahora en el caso de que no se encuentren los datos que solicita el usuario, se muestran ventanas JOptionPane para informar al usuario.
Además añado métodos privados que sirvan de apoyo.

Por ejemplo, el método Ganador_de_Campo recibe por argumentos el nombre de un deporte. Así que hay que consultar que jugadores participan en ese deporte, y de ellos, indicar quien es el ganador según su resultado final.
Para facilitar esto, primero se invoca a un método de apoyo que genera un Vector que contiene una selección de los Jugadores que coinciden con ese deporte.
Una vez obtenido este Vector, ahora sí, buscamos quien es el que tiene mayor puntuacion y retornamos su nombre.

Lee con detenimiento esta clase, pues es el núcleo de todo el programa y es la más importante de comprender. Si algo no lo entiendes, solo tienes que preguntarlo:
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
mport java.util.Vector;
 
import javax.swing.JOptionPane;
 
public class Juegos_Deportivos {
	private Vector<Jugador_de_Campo> Jugadores_de_Campo;
	private Vector<Pesista> Pesistas;
 
	public Juegos_Deportivos() {
		Jugadores_de_Campo = new Vector<Jugador_de_Campo>();
		Pesistas= new Vector<Pesista>();
	}
 
	public void insertar_pesista(String nombre, String pais, float peso, float envion, float palanqueta, float arranque) {
		Pesistas.addElement(new Pesista(nombre,pais,peso,envion,palanqueta,arranque));
	}
 
	public void insertar_Jugador_de_Campo(String nombre, String pais, String deporte, float[] resultados) {
		Jugadores_de_Campo.addElement(new Jugador_de_Campo(nombre,pais,deporte,resultados));
	}
 
	public String Ganador_de_Campo(String deporte){
 
		//Pedimos un Vector con SOLO los jugadores correspondientes a este deporte
		Vector<Jugador_de_Campo> jugadores = getJugadoresDeporte(deporte);
		if (jugadores.isEmpty()) {
			JOptionPane.showMessageDialog(null, "No hay Jugadores para el Deporte: " + deporte,
					"Jugadores de Campo", JOptionPane.WARNING_MESSAGE);
			return null;
		}
		else {
			//Si hay Jugadores para este Deporte, buscamos al ganador
			float mayor = 0;
			String nombre = "";
			for (Jugador_de_Campo jugador: jugadores)
				if (jugador.getResultado_Final() > mayor) {
					mayor = jugador.getResultado_Final();
					nombre = jugador.getNombre();
				}
			return nombre;
		}
	}
 
	/*
	 * Metodo de apoyo.
	 * Devuelve un Vector con los jugadores que coinciden con el deporte indicado
	 */
	private Vector<Jugador_de_Campo> getJugadoresDeporte(String deporte) {
		Vector<Jugador_de_Campo> jugadores = new Vector<Jugador_de_Campo>();
		for (Jugador_de_Campo jugador: Jugadores_de_Campo)
			if (jugador.getDeporte().equals(deporte))
				jugadores.addElement(jugador);
 
		return jugadores;
	}
 
 
	public Float Mayor_Resultado_de_Jugadores(String jug){
		//Buscamos al Pesista que coincida con el nombre, si es que existe...
		for (Pesista jugador: Pesistas)
			if (jugador.getNombre().equals(jug))
				return jugador.getResultadofinal();
		//Si terminado el bucle no se ha retornado nada, es que no existe este jugador
		JOptionPane.showMessageDialog(null, "No hay ningun Pesista con nombre: " + jug,
				"Pesistas", JOptionPane.WARNING_MESSAGE);
		return null;
	}
 
 
 
	public String Mayor_que_Marca(float pes, float marca) {
		//Hacemos una seleccion de pesistas que coincidan con el peso indicado
		Vector<Pesista> seleccion = pesistasPorPeso(pes);
		if (seleccion.isEmpty()) {
			JOptionPane.showMessageDialog(null, "No hay Pesistas para el peso: " + pes,
					"Pesistas", JOptionPane.WARNING_MESSAGE);
			return null;
		}
		else {
			//Buscamos quienes superan la marca. Pueden ser varios, los juntaremos en un String
			String superanMarca = "";
			for (Pesista pesista: seleccion)
				if (pesista.getResultadofinal() > marca)
					superanMarca += pesista.getNombre() + " ";
			//Comprobamos si hemos encontrado alguno
			if (superanMarca.isEmpty()) {
				JOptionPane.showMessageDialog(null, "Ningun Pesista supera la marca: " + marca,
						"Pesistas", JOptionPane.WARNING_MESSAGE);
				return null;
			}
			else
				return superanMarca;
 
		}
	}
 
	/*
	 * Metodo de apoyo.
	 * Retorna un Vector con una seleccion de Pesistas segun el peso
	 */
	private Vector<Pesista> pesistasPorPeso(float peso) {
		Vector<Pesista> seleccionPesistas = new Vector<Pesista>();
		for (Pesista pesista: Pesistas)
			if (pesista.getPeso() == peso)
				seleccionPesistas.addElement(pesista);
 
		return seleccionPesistas;
 
	}
}

Por último, la clase que genera la interfaz.

Esta apenas he hecho cambios, porque como dije antes, es una locura interpretar el código generado por NetBeans.
He quitado las variables que usabas como indices para los arrays primitivos, puesto que ahora no son necesarios al usar la clase Vector.

Creo que no he cambiado nada más.... ahora parece que ya funcionan bien todos los botones. Aunque sigue siendo una interfaz un poco confusa.
Es cierto que hay alguna cosa que es un poco dificil de implementar, por ejemplo, un Jugador_de_Campo puede tener varios Intentos y hay que guardar un Resultado para cada intento.
Gestionar esto solo con un JTextfield es dificil. Lo has hecho, pero es confuso para quien no se ha leido el código. Y claro, un programa ha de ser entendible y fácil de usar para todo el mundo.
Habría que implementar otra forma de hacerlo, quizás un subformulario a parte...

En fin, ahora mismo, funciona bien.
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
public class Interfaz_Proyecto extends javax.swing.JFrame {
 
    /**
     * Creates new form
     */
    private Juegos_Deportivos jue;
    float[] resultado;
 
    public Interfaz_Proyecto() {
        initComponents();
        jue = new Juegos_Deportivos();
    }
 
    /**
     * 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cantpas = new javax.swing.JTextField();
        cantcamp = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        pais = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        peso = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        envion = new javax.swing.JTextField();
        palanqueta = new javax.swing.JTextField();
        arranque = new javax.swing.JTextField();
        Guardar_datos_pesista = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        nombrec = new javax.swing.JTextField();
        paisc = new javax.swing.JTextField();
        deporte = new javax.swing.JTextField();
        intentos = new javax.swing.JTextField();
        resultados = new javax.swing.JTextField();
        Guardar_datos_deportista = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        nomgan = new javax.swing.JTextField();
        mostrarnomgan = new javax.swing.JButton();
        labnomgan = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        nomresfin = new javax.swing.JTextField();
        mostrarresfin = new javax.swing.JButton();
        labresfin = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        marca = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        pesosup = new javax.swing.JTextField();
        mostrarrequisito = new javax.swing.JButton();
        jLabel20 = new javax.swing.JLabel();
        labreq = new javax.swing.JLabel();
        Guardar_resultados = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jLabel1.setText("Cantidad de deportistas de campo");
 
        jLabel2.setText("Cantidad de pesistas");
 
        cantpas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantpasActionPerformed(evt);
            }
        });
 
        jLabel3.setText("Nombre del pesista");
 
        jLabel4.setText("País que representa");
 
        jLabel5.setText("Peso");
 
        peso.setText("0");
        peso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesoActionPerformed(evt);
            }
        });
 
        jLabel6.setText("Resultado envion");
 
        jLabel7.setText("Resultado Palanqueta");
 
        jLabel8.setText("Resultado Arranque");
 
        envion.setText("0");
        envion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                envionActionPerformed(evt);
            }
        });
 
        palanqueta.setText("0");
 
        arranque.setText("0");
        arranque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arranqueActionPerformed(evt);
            }
        });
 
        Guardar_datos_pesista.setText("Guardar");
        Guardar_datos_pesista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_pesistaActionPerformed(evt);
            }
        });
 
        jLabel9.setText("Nombre");
 
        jLabel10.setText("País");
 
        jLabel11.setText("Deporte");
 
        jLabel12.setText("Intentos");
 
        jLabel13.setText("Resultados");
 
        nombrec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombrecActionPerformed(evt);
            }
        });
 
        paisc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paiscActionPerformed(evt);
            }
        });
 
        intentos.setText("0");
 
        resultados.setText("0");
        resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resultadosActionPerformed(evt);
            }
        });
 
        Guardar_datos_deportista.setText("Guardar");
        Guardar_datos_deportista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_datos_deportistaActionPerformed(evt);
            }
        });
 
        jLabel14.setText("Inserte nombre del deporte de campo para conocer su ganador");
 
        mostrarnomgan.setText("Mostrar");
        mostrarnomgan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarnomganActionPerformed(evt);
            }
        });
 
        labnomgan.setText("...");
 
        jLabel16.setText("Inserte el nombre de un deportista par saber su resultado final");
 
        nomresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomresfinActionPerformed(evt);
            }
        });
 
        mostrarresfin.setText("Mostrar");
        mostrarresfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarresfinActionPerformed(evt);
            }
        });
 
        labresfin.setText("...");
 
        jLabel18.setText("Establesca la marca a superar por los pesistas");
 
        marca.setText("0");
        marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                marcaActionPerformed(evt);
            }
        });
 
        jLabel19.setText("Establesca en que peso se debe comprovar");
 
        pesosup.setText("0");
 
        mostrarrequisito.setText("Mostrar");
        mostrarrequisito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mostrarrequisitoActionPerformed(evt);
            }
        });
 
        jLabel20.setText("Quien cumplio con el requisito fue:");
 
        labreq.setText("...");
 
        Guardar_resultados.setText("Guardar resultados");
        Guardar_resultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_resultadosActionPerformed(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()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(mostrarrequisito)
                        .addGap(37, 37, 37)
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labreq))
                    .addComponent(jLabel16)
                    .addComponent(jLabel14)
                    .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_datos_deportista)
                    .addComponent(jLabel2)
                    .addComponent(Guardar_datos_pesista)
                    .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(nombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4)
                            .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(envion))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(55, 55, 55)
                                .addComponent(jLabel10)
                                .addGap(61, 61, 61)
                                .addComponent(jLabel11)
                                .addGap(173, 173, 173)
                                .addComponent(jLabel13)))
                        .addGap(18, 18, 18)
                        .addComponent(Guardar_resultados))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(mostrarnomgan)
                        .addGap(31, 31, 31)
                        .addComponent(labnomgan, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(mostrarresfin)
                        .addGap(36, 36, 36)
                        .addComponent(labresfin))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cantpas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(envion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(palanqueta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(arranque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(Guardar_datos_pesista)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cantcamp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombrec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(paisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(intentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resultados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Guardar_resultados))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Guardar_datos_deportista)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomgan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarnomgan)
                    .addComponent(labnomgan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomresfin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mostrarresfin)
                    .addComponent(labresfin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(marca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pesosup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(mostrarrequisito))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel20)
                        .addComponent(labreq)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void cantpasActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void envionActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void arranqueActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void nombrecActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void paiscActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarnomganActionPerformed(java.awt.event.ActionEvent evt) {
 
        labnomgan.setText(jue.Ganador_de_Campo(nomgan.getText()));
    }
 
    private void nomresfinActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void mostrarresfinActionPerformed(java.awt.event.ActionEvent evt) {
 
        float asd=jue.Mayor_Resultado_de_Jugadores(nomresfin.getText());
        labresfin.setText(""+asd);
 
    }
 
    private void marcaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    private void Guardar_datos_pesistaActionPerformed(java.awt.event.ActionEvent evt) {
 
        int c = Integer.parseInt(peso.getText());
        int d = Integer.parseInt(envion.getText());
        int e = Integer.parseInt(palanqueta.getText());
        int f = Integer.parseInt(arranque.getText());
        System.out.println(nombre.getText()+""+ pais.getText()+""+ c+""+""+""+ d+""+ e+""+ f+"");
        jue.insertar_pesista(nombre.getText(), pais.getText(), c, d, e, f);
    }
 
    private void Guardar_datos_deportistaActionPerformed(java.awt.event.ActionEvent evt) {
        jue.insertar_Jugador_de_Campo(nombrec.getText(), paisc.getText(), deporte.getText(), getResultado());
    }
 
    private void Guardar_resultadosActionPerformed(java.awt.event.ActionEvent evt) {
        int x = Integer.parseInt(intentos.getText());
        float resultado[] = new float[x];
        for (int i = 0; i < x; i++) {
            int y = Integer.parseInt(resultados.getText());
            resultado[i] = y;
        }
        setResultados(resultado);
    }
 
    private void mostrarrequisitoActionPerformed(java.awt.event.ActionEvent evt) {
 
        float g= Integer.parseInt(marca.getText());
        float h = Integer.parseInt(pesosup.getText());
        labreq.setText(jue.Mayor_que_Marca(h, g));
    }
 
    private void pesoActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
 
    /**
     * @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(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interfaz_Proyecto.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 Interfaz_Proyecto().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton Guardar_datos_deportista;
    private javax.swing.JButton Guardar_datos_pesista;
    private javax.swing.JButton Guardar_resultados;
    private javax.swing.JTextField arranque;
    private javax.swing.JTextField cantcamp;
    private javax.swing.JTextField cantpas;
    private javax.swing.JTextField deporte;
    private javax.swing.JTextField envion;
    private javax.swing.JTextField intentos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    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.JLabel labnomgan;
    private javax.swing.JLabel labreq;
    private javax.swing.JLabel labresfin;
    private javax.swing.JTextField marca;
    private javax.swing.JButton mostrarnomgan;
    private javax.swing.JButton mostrarrequisito;
    private javax.swing.JButton mostrarresfin;
    private javax.swing.JTextField nombre;
    private javax.swing.JTextField nombrec;
    private javax.swing.JTextField nomgan;
    private javax.swing.JTextField nomresfin;
    private javax.swing.JTextField pais;
    private javax.swing.JTextField paisc;
    private javax.swing.JTextField palanqueta;
    private javax.swing.JTextField peso;
    private javax.swing.JTextField pesosup;
    private javax.swing.JTextField resultados;
    // End of variables declaration                   
 
    private void setResultados(float[] resultado) {
        this.resultado=resultado;
    }
 
    public float[] getResultado() {
        return resultado;
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar
sin imagen de perfil
Val: 55
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Daniel (19 intervenciones) el 20/06/2019 01:53:22
Guuuuaaaaaaooooooo eres una persona realmente increible por eso eres el #1
Ya me has ayudado 2 veces con 2 progrmas en menos de 10 dias
te lo agradesco mucho no se si lo tienes pero deberias tener un canal de youtube o algo parecido, te iría muy bien
una vez mas gracias
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
Imágen de perfil de Kabuto
Val: 3.428
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas al guardar datos del objeto

Publicado por Kabuto (1381 intervenciones) el 20/06/2019 15:19:50
Jaja.
Lo que pasa es que tengo unos dias libres y mato el tiempo echando una mano en lo que puedo.
Luego cuando vuelva al trabajo ya no tendré tanto tiempo para estas cosas, ni aún menos para llevar un canal Youtube....aunque si supiera que me iba a dar dinero suficiente como para dejar el trabajo....

Por cierto, he creado una interfaz nueva desde cero.
pesistas2

He separado en 4 paneles: 2 para Registrar y Consultar Pesista, otros dos para Registrar y Consultar Jugadores de Campo.
Cada panel está escrito como una clase anidada dentro de la clase NuevaInterfaz, así como los ActionListener de cada botón.

Además arriba de todo hay otro panel que va contando los Deportistas que se van registrando para cada uno de los dos tipos.

Para los jugadores de campo, lo de pedir al usuario cuantos intentos va a querer registrar para ese Jugador, lo he resuelto pregúntandole el número de intentos en la interfaz principal y los valores para esos intentos se los pido en una segunda ventana (un JDialog) que tendrá tantos campos de texto como haya pedido el usuario.
Este JDialog recibe como parametro el array de float para cuando se pulse el boton aceptar, se guardan los datos que haya introducido y así ya podemos crear el nuevo Jugador_de_Campo.

Para adaptarlo he hecho algún pequeño cambio en alguna de las otras clases. Para no volver a pegar aquí toneladas de texto, adjunto todas las clases en un archivo zip para quien pueda serle útil.

Si alguna parte del código no se entiende, preguntadlo por aquí.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar