IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Agents de placement/Fenêtres Java Discussion :

Pourquoi le contenu de ma page ne s'affiche pas ?


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2015
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Pourquoi le contenu de ma page ne s'affiche pas ?
    Bonjour,

    Je suis nouvelle sur le forum et je sais pas trop s'il fallait que je poste la chose ainsi.
    J'ai actuellement un projet dans le cadre de mes études qui consiste à faire un jeu de carte en JAVA.
    J'ai réussi à implémenter toute la partie modèle mais je rencontre des difficultés avec la partie vue.

    Mon affichage est un peu complexe et je suis une novice en la matière auriez-vous une idée de pourquoi au lancement du programme seule la fenêtre et la barre de navigation est visible et que le contenu lui ne s'affiche pas ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    package Vue;
     
    import Modele.Carte;
    import Modele.CarteEnchantement;
    import Modele.CarteMonstre;
    import Modele.Joueur;
    import Modele.JoueurHumain;
    import Modele.Plateau;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
     
     
    public final class Vue extends JFrame{
     
        int tailleFenetreX = 1024;
        int tailleFenetreY = 768;
        int marge = 128;
     
        /* MENU */
        private final JMenuBar barreDeNavigation;
        private final JMenu nouvellePatrie;
        private final JMenuItem unJoueur;
        private final JMenuItem deuxJoueurs;
        private final JMenu aPropos;
     
        /* CONTENU */
        public JPanel fenetre = new JPanel();
     
        /* MESSAGE D'INFORMATION */
        private final JOptionPane info;
     
     
        //////////////////////
        //    CONSTRUCTOR   //
        //////////////////////
     
        public Vue() {
     
            /* FENETRE */
            this.setTitle("Creatures' fight  (pré-alpha)");
            this.setSize(tailleFenetreX, tailleFenetreY);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLayout(new BorderLayout()); 
            this.setResizable(true);
     
            /* MENU */
            barreDeNavigation = new JMenuBar();
            nouvellePatrie = new JMenu("Nouvelle Partie");
            unJoueur = new JMenuItem("Un Joueur");
            deuxJoueurs = new JMenuItem("Deux Joueurs");
            aPropos = new JMenu("A propos"); 
            nouvellePatrie.add(unJoueur);
            nouvellePatrie.add(deuxJoueurs);
            barreDeNavigation.add(nouvellePatrie);
            barreDeNavigation.add(aPropos);
            this.setJMenuBar(barreDeNavigation);
     
            /* MESSAGE D'INFORMATION */
            info = new JOptionPane();
     
            /* AJOUT A LA FENETRE */
     
            JPanel contenuFenetre = constructionContenuVide();
            fenetre.add(contenuFenetre);
     
            this.setContentPane(fenetre);
            this.setVisible(true);	
        }
     
        public Vue(Joueur j1, Joueur j2, Plateau plateau) {
     
            /* FENETRE */
            this.setTitle("Creatures' fight  (pré-alpha)");
            this.setSize(tailleFenetreX, tailleFenetreY);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLayout(new BorderLayout()); 
            this.setResizable(true);
     
            /* MENU */
            this.barreDeNavigation = new JMenuBar();
            this.nouvellePatrie = new JMenu("Nouvelle Partie");
            this.unJoueur = new JMenuItem("Un Joueur");
            this.deuxJoueurs = new JMenuItem("Deux Joueurs");
            this.aPropos = new JMenu("A propos"); 
            nouvellePatrie.add(unJoueur);
            nouvellePatrie.add(deuxJoueurs);
            barreDeNavigation.add(nouvellePatrie);
            barreDeNavigation.add(aPropos);
            this.setJMenuBar(barreDeNavigation);
     
            /* MESSAGE D'INFORMATION */
            this.info = new JOptionPane();
     
            /* AJOUT A LA FENETRE */
            this.fenetre = new JPanel();
            this.fenetre = constructionContenuFenetre(j1, j2, plateau);
     
            this.setVisible(true);	
        }
     
     
        JPanel constructionContenuGauche(Joueur j1, Joueur j2){
            /* RESULTAT */
            JPanel contenuGauche = new JPanel();
            contenuGauche.setPreferredSize(new Dimension(marge, tailleFenetreY));
            contenuGauche.setLayout(new GridBagLayout());
     
            /* LES JLABELS */
            JLabel nomJoueur1 = new JLabel();
            nomJoueur1.setText("JOUEUR 1");
            JLabel pvJoueur1 = new JLabel();
            pvJoueur1.setText("Pv : " + j1.getPv());
            JLabel ressourcesJoueur1 = new JLabel();
            ressourcesJoueur1.setText("Ressources : " + j1.getRessources());
            JLabel nomJoueur2 = new JLabel();
            nomJoueur2.setText("JOUEUR 2");
            JLabel pvJoueur2 = new JLabel();
            pvJoueur2.setText("Pv : " + j2.getPv());
            JLabel ressourcesJoueur2 = new JLabel();
            ressourcesJoueur2.setText("Ressources : " + j2.getRessources());
     
            /* LES JPANELS */
            JPanel cell1 = new JPanel();    // Nom joureur 1
            cell1.add(nomJoueur1);
            cell1.setPreferredSize(new Dimension(marge,15));
            JPanel cell2 = new JPanel();    // Pv joureur 1
            cell2.add(pvJoueur1);
            cell2.setPreferredSize(new Dimension(marge,15));
            JPanel cell3 = new JPanel();    // Ressources joureur 1
            cell3.add(ressourcesJoueur1);
            cell3.setPreferredSize(new Dimension(marge,15));
            JPanel cell4 = new JPanel();    // Nom joureur 2
            cell4.add(nomJoueur2);
            cell4.setPreferredSize(new Dimension(marge,15));
            JPanel cell5 = new JPanel();    // Pv joureur 2
            cell5.add(pvJoueur2);
            cell5.setPreferredSize(new Dimension(marge,15));
            JPanel cell6 = new JPanel();    // Ressources joureur 2
            cell6.add(ressourcesJoueur2);
            cell6.setPreferredSize(new Dimension(marge,15));
     
            /* POSITIONNEMENT DES COMPOSANTS */
            GridBagConstraints gbc = new GridBagConstraints();
            // JOUEUR 1
            // Nom
            gbc.gridx = 0;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell1, gbc);
            // Pv
            gbc.gridx = 0;
            gbc.gridy = 1; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell2, gbc);
            // Ressources
            gbc.gridx = 0;
            gbc.gridy = 3; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell3, gbc);
     
            // JOUEUR 2
            // Nom
            gbc.gridx = 0;
            gbc.gridy = 4; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell4, gbc);
            // Pv
            gbc.gridx = 0;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell5, gbc);
            // Ressources
            gbc.gridx = 0;
            gbc.gridy = 6; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuGauche.add(cell6, gbc);
     
            return contenuGauche;
        }
     
        JPanel constructionContenuCentre(Plateau plateau){
            int i;
            /* RESULTAT */
            JPanel contenuCentre = new JPanel();
            contenuCentre.setPreferredSize(new Dimension(tailleFenetreX-marge-marge, tailleFenetreY));
            contenuCentre.setLayout(new GridBagLayout());
     
            /* LES BOUTONS */
            // JOUEUR 1
            ArrayList<Bouton> boutonsJ1Main = new ArrayList<>();            // Main joureur 1
            for(i = 0; i < plateau.getMainJ1().size(); i++){
                if(plateau.getMainJ1().get(i) instanceof CarteMonstre){
                    CarteMonstre carte = (CarteMonstre)plateau.getMainJ1().get(i);
                    BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                    boutonsJ1Main.add(bouton);
                }
                if(plateau.getMainJ1().get(i) instanceof CarteEnchantement){
                    CarteEnchantement carte = (CarteEnchantement)plateau.getMainJ1().get(i);
                    BoutonCarteEnchantement bouton = new BoutonCarteEnchantement(carte); 
                    boutonsJ1Main.add(bouton);
                }
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ1Main.add(bouton);
            }
            ArrayList<Bouton> boutonsJ1Terrain = new ArrayList<>();         // Terrain joureur 1
            for(i = 0; i < plateau.getTerrainJ1().size(); i++){
                CarteMonstre carte = (CarteMonstre)plateau.getTerrainJ1().get(i);
                BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                boutonsJ1Terrain.add(bouton);
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ1Terrain.add(bouton);
            }
            ArrayList<Bouton> boutonsJ1LigneDeCombat = new ArrayList<>();   // Ligne de combat joureur 1
            for(i = 0; i < plateau.getLigneCombatJ1().size(); i++){
                CarteMonstre carte = (CarteMonstre)plateau.getLigneCombatJ1().get(i);
                BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                boutonsJ1LigneDeCombat.add(bouton);
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ1LigneDeCombat.add(bouton);
            }
            // JOUEUR 2
            ArrayList<Bouton> boutonsJ2Main = new ArrayList<>();            // Main joureur 2
            for(i = 0; i < plateau.getMainJ2().size(); i++){
                if(plateau.getMainJ2().get(i) instanceof CarteMonstre){
                    CarteMonstre carte = (CarteMonstre)plateau.getMainJ2().get(i);
                    BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                    boutonsJ2Main.add(bouton);
                }
                if(plateau.getMainJ2().get(i) instanceof CarteEnchantement){
                    CarteEnchantement carte = (CarteEnchantement)plateau.getMainJ2().get(i);
                    BoutonCarteEnchantement bouton = new BoutonCarteEnchantement(carte); 
                    boutonsJ2Main.add(bouton);
                }
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ2Main.add(bouton);
            }
            ArrayList<Bouton> boutonsJ2Terrain = new ArrayList<>();         // Terrain joureur 2
            for(i = 0; i < plateau.getTerrainJ2().size(); i++){
                CarteMonstre carte = (CarteMonstre)plateau.getTerrainJ2().get(i);
                BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                boutonsJ2Terrain.add(bouton);
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ2Terrain.add(bouton);
            }
            ArrayList<Bouton> boutonsJ2LigneDeCombat = new ArrayList<>();   // Ligne de combat joureur 2
            for(i = 0; i < plateau.getLigneCombatJ2().size(); i++){
                CarteMonstre carte = (CarteMonstre)plateau.getLigneCombatJ2().get(i);
                BoutonCarteMonstre bouton = new BoutonCarteMonstre(carte); 
                boutonsJ2LigneDeCombat.add(bouton);
            }
            for(int j = i; j < 4; j++){
                BoutonSansCarte bouton = new BoutonSansCarte();
                boutonsJ2LigneDeCombat.add(bouton);
            }
     
            // JOUEUR 1
            // Main
            JPanel cell1 = new JPanel();    
            cell1.add(boutonsJ1Main.get(0));
            cell1.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell2 = new JPanel();
            cell2.add(boutonsJ1Main.get(1));
            cell2.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell3 = new JPanel();    
            cell3.add(boutonsJ1Main.get(2));
            cell3.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell4 = new JPanel();    
            cell4.add(boutonsJ1Main.get(3));
            cell4.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            // Terrain
            JPanel cell5 = new JPanel();    
            cell5.add(boutonsJ1Terrain.get(0));
            cell5.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell6 = new JPanel();
            cell6.add(boutonsJ1Terrain.get(1));
            cell6.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell7 = new JPanel();    
            cell7.add(boutonsJ1Terrain.get(2));
            cell7.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell8 = new JPanel();    
            cell8.add(boutonsJ1Terrain.get(3));
            cell8.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            // Ligne de combat
            JPanel cell9 = new JPanel();    
            cell9.add(boutonsJ1LigneDeCombat.get(0));
            cell9.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell10 = new JPanel();
            cell10.add(boutonsJ1LigneDeCombat.get(1));
            cell10.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell11 = new JPanel();    
            cell11.add(boutonsJ1LigneDeCombat.get(2));
            cell11.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell12 = new JPanel();    
            cell12.add(boutonsJ1LigneDeCombat.get(3));
            cell12.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            // JOUEUR 2
            // Main
            JPanel cell13 = new JPanel();    
            cell13.add(boutonsJ1Main.get(0));
            cell13.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell14 = new JPanel();
            cell14.add(boutonsJ1Main.get(1));
            cell14.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell15 = new JPanel();    
            cell15.add(boutonsJ1Main.get(2));
            cell15.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell16 = new JPanel();    
            cell16.add(boutonsJ1Main.get(3));
            cell16.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            // Terrain
            JPanel cell17 = new JPanel();    
            cell17.add(boutonsJ1Terrain.get(0));
            cell17.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell18 = new JPanel();
            cell18.add(boutonsJ1Terrain.get(1));
            cell18.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell19 = new JPanel();    
            cell19.add(boutonsJ1Terrain.get(2));
            cell19.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell20 = new JPanel();    
            cell20.add(boutonsJ1Terrain.get(3));
            cell20.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            // Ligne de combat
            JPanel cell21 = new JPanel();    
            cell21.add(boutonsJ1LigneDeCombat.get(0));
            cell21.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell22 = new JPanel();
            cell22.add(boutonsJ1LigneDeCombat.get(1));
            cell22.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell23 = new JPanel();    
            cell23.add(boutonsJ1LigneDeCombat.get(2));
            cell23.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
            JPanel cell24 = new JPanel();    
            cell24.add(boutonsJ1LigneDeCombat.get(3));
            cell24.setPreferredSize(new Dimension((tailleFenetreX-marge-marge)/4,tailleFenetreY/6));
     
            /* POSITIONNEMENT DES COMPOSANTS */
            GridBagConstraints gbc = new GridBagConstraints();
            // JOUEUR 1
            // Main
            gbc.gridx = 0;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell1, gbc);
            gbc.gridx = 1;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell2, gbc);
            gbc.gridx = 2;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell3, gbc);
            gbc.gridx = 3;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell4, gbc);
            // Terrain
            gbc.gridx = 0;
            gbc.gridy = 1; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell5, gbc);
            gbc.gridx = 1;
            gbc.gridy = 1; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell6, gbc);
            gbc.gridx = 2;
            gbc.gridy = 1; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell7, gbc);
            gbc.gridx = 3;
            gbc.gridy = 1; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell8, gbc);
            // Ligne de Combat
            gbc.gridx = 0;
            gbc.gridy = 2; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell9, gbc);
            gbc.gridx = 1;
            gbc.gridy = 2; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell10, gbc);
            gbc.gridx = 2;
            gbc.gridy = 2; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell11, gbc);
            gbc.gridx = 3;
            gbc.gridy = 2; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell12, gbc);
            // JOUEUR 2
            // Main
            gbc.gridx = 0;
            gbc.gridy = 3; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell13, gbc);
            gbc.gridx = 1;
            gbc.gridy = 3; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell14, gbc);
            gbc.gridx = 2;
            gbc.gridy = 3; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell15, gbc);
            gbc.gridx = 3;
            gbc.gridy = 3; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell16, gbc);
            // Terrain
            gbc.gridx = 0;
            gbc.gridy = 4; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell17, gbc);
            gbc.gridx = 1;
            gbc.gridy = 4; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell18, gbc);
            gbc.gridx = 2;
            gbc.gridy = 4; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell19, gbc);
            gbc.gridx = 3;
            gbc.gridy = 4; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell20, gbc);
            // Ligne de Combat
            gbc.gridx = 0;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell21, gbc);
            gbc.gridx = 1;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell22, gbc);
            gbc.gridx = 2;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell23, gbc);
            gbc.gridx = 3;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuCentre.add(cell24, gbc);
     
            return contenuCentre;
        }
     
        JPanel constructionContenuDroit(){
            /* RESULTAT */
            JPanel contenuDroit = new JPanel();
            contenuDroit.setPreferredSize(new Dimension(marge, tailleFenetreY));
            contenuDroit.setLayout(new GridBagLayout()); 
     
            /* LE BOUTON */
            BoutonPhaseTerminee bouton = new BoutonPhaseTerminee();
     
            /* JPANEL */
            JPanel cell = new JPanel();    
            cell.add(bouton);
            cell.setPreferredSize(new Dimension(marge,tailleFenetreY/9));
     
            /* POSITIONNEMENT DES COMPOSANTS */
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 5; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuDroit.add(cell, gbc);
     
            return contenuDroit;
        }
     
        JPanel constructionContenuFenetre(Joueur j1, Joueur j2, Plateau plateau){
            /* RESULTAT */
            JPanel contenuFenetre = new JPanel();
            contenuFenetre.setPreferredSize(new Dimension(tailleFenetreX, tailleFenetreY));
            contenuFenetre.setLayout(new GridBagLayout());
     
            /* NOS CONTENEURS */
            JPanel contenuGauche = constructionContenuGauche(j1, j2);
            JPanel contenuCentre = constructionContenuCentre(plateau);
            JPanel contenuDroit = constructionContenuDroit();
     
             /* JPANEL */
            JPanel cell1 = new JPanel();    
            cell1.add(contenuGauche);
        //    cell1.setPreferredSize(new Dimension(marge,tailleFenetreY));
            JPanel cell2 = new JPanel();    
            cell2.add(contenuCentre);
         //   cell2.setPreferredSize(new Dimension(tailleFenetreX-marge-marge,tailleFenetreY));
            JPanel cell3 = new JPanel();    
            cell3.add(contenuDroit);
         //   cell3.setPreferredSize(new Dimension(marge,tailleFenetreY));
     
            /* POSITIONNEMENT DES COMPOSANTS */
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell1, gbc);
            gbc.gridx = 1;
            gbc.gridy = 0; 
            gbc.gridheight = 6;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell2, gbc);
            gbc.gridx = 7;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell3, gbc);
     
            return contenuFenetre;
        }
     
        JPanel constructionContenuVide(){
            /* RESULTAT */
            JPanel contenuFenetre = new JPanel();
            contenuFenetre.setPreferredSize(new Dimension(tailleFenetreX, tailleFenetreY));
            contenuFenetre.setLayout(new GridBagLayout());
     
            /* PLATEAU VIDE */
            ArrayList<Carte> main_j1 = new ArrayList<>();
            ArrayList<Carte> main_j2 = new ArrayList<>();
            Plateau plateauVide = new Plateau(main_j1, main_j2);
     
            /* JOUEURS DE DEPART */
            Joueur j1 = new JoueurHumain(1);
            Joueur j2 = new JoueurHumain(2);
     
            /* NOS CONTENEURS */
            JPanel contenuGauche = new JPanel();
            contenuGauche = constructionContenuGauche(j1, j2);
            JPanel contenuCentre = new JPanel();
            contenuCentre = constructionContenuCentre(plateauVide);
            JPanel contenuDroit = new JPanel();
            contenuDroit = constructionContenuDroit();
     
             /* JPANEL */
            JPanel cell1 = new JPanel();    
            cell1.add(contenuGauche);
        //    cell1.setPreferredSize(new Dimension(marge,tailleFenetreY));
            JPanel cell2 = new JPanel();    
            cell2.add(contenuCentre);
         //   cell2.setPreferredSize(new Dimension(tailleFenetreX-marge-marge,tailleFenetreY));
            JPanel cell3 = new JPanel();    
            cell3.add(contenuDroit);
         //   cell3.setPreferredSize(new Dimension(marge,tailleFenetreY));
     
            /* POSITIONNEMENT DES COMPOSANTS */
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell1, gbc);
            gbc.gridx = 1;
            gbc.gridy = 0; 
            gbc.gridheight = 6;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell2, gbc);
            gbc.gridx = 7;
            gbc.gridy = 0; 
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            contenuFenetre.add(cell3, gbc);
     
            return contenuFenetre;
        }
     
        void majVue(Joueur j1, Joueur j2, Plateau plateau){
            this.fenetre = constructionContenuFenetre(j1, j2, plateau);
        }
    }
    Merci, par avance aux bonnes âmes qui pourraient m'aider.
    Fichiers attachés Fichiers attachés

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Il semble que le contenu que tu dis ne pas être affiché est celui construit par constructionContenuFenetre() (ou constructionContenuVide(), selon le constructeur de Vue).

    Tu construis un JPanel que tu mets dans une variable fenetre. Mais l'instance de JPanle n'est pas toujours remise dans le conteneur.

    Dans le cas du constructeur sans argument :
    Le variable fenetre est initialisée avec [c]public JPanel fenetre = new JPanel();[/]. On y met un JPanel par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    JPanel contenuFenetre = constructionContenuVide();
    fenetre.add(contenuFenetre);
    Puis le composant est placée dans la fenêtre (conteneur) par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.setContentPane(fenetre);
    Jusque là tout va bien.

    En revanche, dans l'autre constructeur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
       this.fenetre = new JPanel(); // inutile : déjà fait dans la déclaration, et remplacé par la ligne d'après
    this.fenetre = constructionContenuFenetre(j1, j2, plateau);
    La première ligne est inutile : déjà, elle est redondante par rapport à l'initialisation de la déclaration, mais en plus, on la fait pour rien, puis juste après ou réaffecte une nouvelle valeur à la variable fenetre.
    Ensuite, si on met bien une instance de JPanel, créée par la méthode constructionContenuFenetre, on ne la met pas dans la JFrame, donc elle ne se trouve dans aucun conteneur, donc elle ne sera jamais affichée. Il faut au moins faire ce qu'on fait dans le constructeur sans argument :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.setContentPane(fenetre);
    Par ailleurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    void majVue(Joueur j1, Joueur j2, Plateau plateau){
        this.fenetre = constructionContenuFenetre(j1, j2, plateau);
    }
    C'est exactement le même problème ici : le fait de changer la valeur dans la variable n'a aucun effet sur la JFrame. Il faut faire this.setContentPane(fenetre); pour que le contenu change dans la JFrame.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2015
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    Merci beaucoup pour ta réponse complète !
    Je compris et tout marche nickel.

    Un grand merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. le contenu de la page ne s'affiche pas
    Par _fafa dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 27/04/2010, 15h03
  2. <html:errors /> Ma page ne s'affiche pas
    Par Zanton dans le forum Struts 1
    Réponses: 5
    Dernier message: 10/10/2006, 10h33
  3. Réponses: 2
    Dernier message: 19/06/2006, 14h05
  4. [SimpleXML] Le contenu de mon élément ne s'affiche pas
    Par alliance dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 08/05/2006, 20h27
  5. Réponses: 9
    Dernier message: 04/10/2005, 19h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo