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

 Java Discussion :

JDialog qui ouvre une JDialog


Sujet :

Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 35
    Points : 11
    Points
    11
    Par défaut JDialog qui ouvre une JDialog
    Bonjour,
    en faite, j'aimerais avoir une JDialog qui ouvre une JDialog et qui reviens sur la JFrame.
    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
    public class Intro extends javax.swing.JDialog/*MonComponent1*/{protected boolean fermeture=false;Choix jd;
     
     
        public Intro(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
           /* this.setImage();
            this.repaint();*/
            initComponents();
        }
        public Intro(java.awt.Dialog Parent,boolean modal) {
        super(Parent);
        setModal(modal);
        initComponents();
        }
     
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jToggleButton1 = new javax.swing.JToggleButton();
     
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    closeDialog(evt);
                }
            });
            getContentPane().setLayout(new java.awt.GridLayout());
     
            jToggleButton1.setText("Nouveau Jeu");
            jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jToggleButton1ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 416, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(104, Short.MAX_VALUE)))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 311, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(239, Short.MAX_VALUE)
                        .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)))
            );
     
            getContentPane().add(jPanel1);
     
            pack();
        }// </editor-fold>
     
        /** Closes the dialog */
        private void closeDialog(java.awt.event.WindowEvent evt) {                             
            setVisible(false);
            dispose();
        }                            
     
        private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
            fermeture=true;
            jd=new Choix(this,true);
            jd.setVisible(true);
            setVisible(false);
            dispose();
        }                                              
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Intro dialog = new Intro(new java.awt.Frame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }
            });
        }
     
     
        // Variables declaration - do not modify
        private javax.swing.JPanel jPanel1;
        private javax.swing.JToggleButton jToggleButton1;
        // End of variables declaration
     
    }
    1ere JDialog
    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
    public class Choix extends java.awt.Dialog {
    int longueurgrille,largueurgrille,division,nbjeux,nbtour;
     
        public Choix(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }
     
        public Choix(java.awt.Dialog Parent,boolean modal) {
        super(Parent);
        setModal(modal);
        initComponents();
      }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            Long = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            Larg = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            Div = new javax.swing.JTextField();
            jPanel4 = new javax.swing.JPanel();
            jLabel4 = new javax.swing.JLabel();
            nbTour = new javax.swing.JTextField();
            jLabel5 = new javax.swing.JLabel();
            nbJeux = new javax.swing.JTextField();
            jPanel5 = new javax.swing.JPanel();
            Valider = new javax.swing.JButton();
     
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    closeDialog(evt);
                }
            });
            setLayout(new java.awt.GridLayout(2, 2));
            add(jPanel1);
            add(jPanel2);
     
            jPanel3.setLayout(new java.awt.GridLayout(6, 2));
     
            jLabel1.setText("Longueur de la Grille");
            jPanel3.add(jLabel1);
     
            Long.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    LongActionPerformed(evt);
                }
            });
            jPanel3.add(Long);
     
            jLabel2.setText("Largeur de la Grille");
            jPanel3.add(jLabel2);
            jPanel3.add(Larg);
     
            jLabel3.setText("Nombres de divisions");
            jPanel3.add(jLabel3);
            jPanel3.add(Div);
     
            add(jPanel3);
     
            jPanel4.setLayout(new java.awt.GridLayout(3, 2));
     
            jLabel4.setText("Nombre de Tour");
            jPanel4.add(jLabel4);
            jPanel4.add(nbTour);
     
            jLabel5.setText("Nombre de Jeux");
            jPanel4.add(jLabel5);
            jPanel4.add(nbJeux);
            jPanel4.add(jPanel5);
     
            Valider.setText("VALIDER");
            Valider.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ValiderActionPerformed(evt);
                }
            });
            jPanel4.add(Valider);
     
            add(jPanel4);
     
            pack();
        }// </editor-fold>                        
     
        /** Closes the dialog */
        private void closeDialog(java.awt.event.WindowEvent evt) {                             
            setVisible(false);
            dispose();
        }                            
     
        private void LongActionPerformed(java.awt.event.ActionEvent evt) {                                     
     
        }                                    
     
        private void ValiderActionPerformed(java.awt.event.ActionEvent evt) {                                        
         int i=Integer.parseInt(Long.getText());
          if(i<0)
           System.out.println("erreur de la longueur");
          else
            longueurgrille=i;
     
     
         int j=Integer.parseInt(Larg.getText());
         if(j<0)
           System.out.println("erreur de la largueur");
          else
            largueurgrille=j;
     
         int k=Integer.parseInt(Div.getText());
         if(k<0)
           System.out.println("erreur de la division");
          else
            division=k;
     
         int l=Integer.parseInt(nbTour.getText());
         if(l<0)
           System.out.println("erreur du nombre de tours");
          else
            nbtour=l;
     
         int m=Integer.parseInt(nbJeux.getText());
         if(m<0)
           System.out.println("erreur du nombre de jeux");
          else
            nbjeux=m;
       System.out.println(m);
         setVisible(false);
            dispose();
        }                                       
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Choix dialog = new Choix(new java.awt.Frame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }
            });
        }
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JTextField Div;
        private javax.swing.JTextField Larg;
        private javax.swing.JTextField Long;
        private javax.swing.JButton Valider;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JPanel jPanel4;
        private javax.swing.JPanel jPanel5;
        private javax.swing.JTextField nbJeux;
        private javax.swing.JTextField nbTour;
        // End of variables declaration                   
     
    }
    2éme JDialog
    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
    public PlateauJeu(){
     
           initComponents(); 
           Intro i=new Intro(this,true); i.setVisible(true);
           Choix jd=i.jd;
           larg=jd.largueurgrille;
           longu=jd.longueurgrille;
           System.out.println(larg);System.out.println(longu);
           nbto=jd.nbtour;
           nbdiv=jd.division;
           nbje=jd.nbjeux;
          lejeu=new Jeu(longu,larg,nbto,nbdiv,nbje);
           restest.setVisible(false);
           pp.setVisible(false);
           pg.setVisible(false);
           pdr.setVisible(false);
           ResultatPourc.setVisible(false);
           PPerdu.setVisible(false);
           PGagne.setVisible(false);
     
           creationJeu();
           afficheJeu();
     
     
     
        }
    JFrame

    En faite la construction des JDialog sa marche le problème c'est que quand tout ferme sa renvoie pas à la JFrame
    ou est mon erreur???

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 35
    Points : 11
    Points
    11
    Par défaut
    Quelqu'un peut m'aider???
    je veux juste savoir ou est mon erreur et comment la corriger
    svp

  3. #3
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 845
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 845
    Points : 22 859
    Points
    22 859
    Billets dans le blog
    51
    Par défaut
    Déjà 1) pourquoi tu utilises un Dialog au lieu d'un JDialog pour l'une des classes ? et 2) rien ne t'empêche de mettre les listeners (WindowListener) qu'il faut sur tes dialogues pour qu'à leur fermeture tes dialogues remontent la fenêtre racine en lui donnant le focus et en faisant un toFront() dessus.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  4. #4
    Membre confirmé Avatar de javaNavCha
    Homme Profil pro
    EKG Group
    Inscrit en
    Juillet 2009
    Messages
    311
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : EKG Group
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2009
    Messages : 311
    Points : 631
    Points
    631
    Par défaut JDialog et Dialog
    Bonjour,
    je te conseilles d'utiliser un JDialog au lieu de Dialog;
    car le SWING est plus léger que l'AWT;
    Aussi il vaut mieux ajouter un setVisible(true) ; dans le constructeur du premier JDialog; ce dernier une fois instancié, il sera affiché;
    Enfin tu pourras utiliser un FocusLister et l'affecter au premier JDialog: dès qu'il perd le focus le deuxième s'affiche...

    Et Bonne continuation...

    javacha4
    On essaie
    et ça marchera

    Mon site
    Ma page

Discussions similaires

  1. Réponses: 1
    Dernier message: 15/08/2006, 01h39
  2. Formulaire qui ouvre une popup
    Par Mookie dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 07/03/2006, 22h14
  3. [debutant] un bouton qui ouvre une fenetre
    Par dous dans le forum Composants
    Réponses: 6
    Dernier message: 21/11/2005, 09h55
  4. [JDialog] Icône d'une JDialog (bug Java or not ?)
    Par Oliveuh dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 22/07/2005, 12h03
  5. Savoir qui ouvre une form
    Par rvzip64 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 16/07/2004, 16h25

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