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 :

ouvrir une JFrame grace à un JButton


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 25
    Par défaut ouvrir une JFrame grace à un JButton
    Bonsoir et bonne année à tous!!
    je crée une interface graphique en java, et je voudrais savoir comment ouvrir une nouvelle JFrame grace à un JButton!!
    En effet j'ai créé l'interface Connexion et dans cette interface j'ai mis un JButton inscription qui va ouvrir mon interface inscription mais je ne sais pas comment faire!!
    Si quelqu'un peut m'aider ca serait sympa!!
    Merci d'avance et bonne soirée au pied du feu!!!!!
    krikri

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 22
    Par défaut
    bonjour
    pour le faire comme suit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    le_nom_bouton.addAcionListener(new AcionListener(){
        public void actionPerformed(ActionEvent e){
            /*ici instancier votre classe ou se trouve votre fenetre*/
        }
    });

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 25
    Par défaut
    Bonjour à tous!!
    merci de ton aide, j'ai essayé mais il ne veut pas connaitre la classe que je veux instancier!! j'ai oublié de signaler que je travaille avec netBeans!!!
    voici ma classe Inscription qui pour l'instant ne fait rien (pour l'instant je m'occupe du bouton inscription!!)
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * Connexion.java
     *
     * Created on 6 janv. 2009, 18:44:42
     */
     
    /**
     *
     * @author Administrateur
     */
    import java.awt.Event.*;
    public class Connexion extends javax.swing.JFrame {
     
        /** Creates new form Connexion */
        public Connexion() {
            inscription.addActionListener(new ActionListener());
            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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jPasswordField1 = new javax.swing.JPasswordField();
            jButton1 = new javax.swing.JButton();
            inscription = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setName("Form"); // NOI18N
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(monprojet.MonprojetApp.class).getContext().getResourceMap(Connexion.class);
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
     
            jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
            jLabel3.setName("jLabel3"); // NOI18N
     
            jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
            jTextField1.setName("jTextField1"); // NOI18N
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
     
            jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
            jPasswordField1.setName("jPasswordField1"); // NOI18N
     
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
     
            inscription.setText(resourceMap.getString("inscription.text")); // NOI18N
            inscription.setName("inscription"); // NOI18N
            inscription.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    inscriptionMouseClicked(evt);
                }
            });
            inscription.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    inscriptionActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(44, 44, 44)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel3))
                            .addGap(38, 38, 38)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel1)
                                .addComponent(jPasswordField1)
                                .addComponent(jTextField1)))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(81, 81, 81)
                            .addComponent(jButton1)
                            .addGap(34, 34, 34)
                            .addComponent(inscription)))
                    .addContainerGap(121, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(32, 32, 32)
                    .addComponent(jLabel1)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(26, 26, 26)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3))
                    .addGap(71, 71, 71)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(inscription))
                    .addContainerGap(76, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>
     
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void inscriptionMouseClicked(java.awt.event.MouseEvent evt) {
            //employe toto=new employe();
    }
     
        private void inscriptionActionPerformed(java.awt.event.ActionEvent evt) {
            employe toto=new employe();
    }
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Connexion().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton inscription;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JPasswordField jPasswordField1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration
     
    }
    et je voudrais que quand je clic sur inscription j'aille sur cette JFramme (class employe)
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * employe.java
     *
     * Created on 6 janv. 2009, 22:01:55
     */
     
    package monprojet;
     
    /**
     *
     * @author Administrateur
     */
    public class employe extends javax.swing.JFrame {
     
        /** Creates new form employe */
        public employe() {
            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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jTextField4 = new javax.swing.JTextField();
            jPasswordField1 = new javax.swing.JPasswordField();
            Valider = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setName("Form"); // NOI18N
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(monprojet.MonprojetApp.class).getContext().getResourceMap(employe.class);
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
     
            jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
            jLabel3.setName("jLabel3"); // NOI18N
     
            jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
            jLabel4.setName("jLabel4"); // NOI18N
     
            jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
            jLabel5.setName("jLabel5"); // NOI18N
     
            jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
            jTextField1.setName("jTextField1"); // NOI18N
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
     
            jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
            jTextField2.setName("jTextField2"); // NOI18N
     
            jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
            jTextField3.setName("jTextField3"); // NOI18N
            jTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField3ActionPerformed(evt);
                }
            });
     
            jTextField4.setText(resourceMap.getString("jTextField4.text")); // NOI18N
            jTextField4.setName("jTextField4"); // NOI18N
     
            jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
            jPasswordField1.setName("jPasswordField1"); // NOI18N
            jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jPasswordField1ActionPerformed(evt);
                }
            });
     
            Valider.setText(resourceMap.getString("Valider.text")); // NOI18N
            Valider.setName("Valider"); // NOI18N
     
            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(77, 77, 77)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jLabel5)
                        .addComponent(jLabel2))
                    .addGap(85, 85, 85)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                        .addComponent(jPasswordField1)
                        .addComponent(jTextField2)
                        .addComponent(jTextField3)
                        .addComponent(jTextField4))
                    .addGap(18, 18, 18)
                    .addComponent(Valider)
                    .addContainerGap(14, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(45, 45, 45)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(33, 33, 33)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(33, 33, 33)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(32, 32, 32)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(27, 27, 27)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(30, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(266, Short.MAX_VALUE)
                    .addComponent(Valider)
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>                        
     
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
            // TODO add your handling code here:
        }                                               
     
        private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new employe().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        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.JPasswordField jPasswordField1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        private javax.swing.JTextField jTextField4;
        // End of variables declaration                   
     
    }
    si quelqu'un peut m'aider!!
    merci d'avance
    Krikri

  4. #4
    Membre Expert
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Par défaut
    Bonjour, dans ta méthode inscriptionActionPerformed tu instancies bien la JFrame employe mais tu ne l'affiches pas.
    Tu dois ajouter :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    employe.setVisible(true);
    ps : par convention, les noms de classes commencent par une majuscule : Employe.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 25
    Par défaut
    Bonsoir et merci de votre aide!!
    j'ai fait ce que vous m'avez dit et j'ai 2 erreurs (que je ne comprends pas!!)
    je vous remets va class connexion que j'ai modifié comme vous me l'avez dit :
    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
    package monprojet;
     
    /**
     *
     * @author Administrateur
     */
    import java.awt.Event.*;
     
    public class Connexion extends javax.swing.JFrame {
     
        /** Creates new form Connexion */
        public Connexion() {
            inscription.addActionListener(new ActionListener());
     
     
            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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jLabel2 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jLabel3 = new javax.swing.JLabel();
            login = new javax.swing.JTextField();
            mp = new javax.swing.JPasswordField();
            inscription = new javax.swing.JButton();
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(monprojet.MonprojetApp.class).getContext().getResourceMap(Connexion.class);
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setName("Form"); // NOI18N
     
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
                }
            });
     
            jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
            jLabel3.setName("jLabel3"); // NOI18N
     
            login.setText(resourceMap.getString("login.text")); // NOI18N
            login.setName("login"); // NOI18N
     
            mp.setText(resourceMap.getString("mp.text")); // NOI18N
            mp.setName("mp"); // NOI18N
     
            inscription.setText(resourceMap.getString("inscription.text")); // NOI18N
            inscription.setName("inscription"); // NOI18N
            inscription.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    inscriptionActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(141, 141, 141)
                            .addComponent(jButton1)
                            .addGap(30, 30, 30)
                            .addComponent(inscription))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(67, 67, 67)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel1))
                            .addGap(82, 82, 82)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(mp)
                                .addComponent(login, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))))
                    .addContainerGap(65, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(72, 72, 72)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(inscription))
                    .addGap(81, 81, 81))
            );
     
            pack();
        }// </editor-fold>
     
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
           /*ConnexionBDD maConnection=new ConnexionBDD("postgres","coucou","jdbc:postgresql:conges");
     
    			try
    				{
    					connexionemploye.verification(maConnection.connection(),login.getText(),mp.getText());
    				}
    			catch(Exception E)
    				{
    					System.out.println("Verification ne fonctionne pas!!");
    				}*/
        }                                     
     
        private void inscriptionActionPerformed(java.awt.event.ActionEvent evt) {
          employe toto=new employe();
          employe.setVisible(true);
     
    }
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Connexion().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton inscription;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JTextField login;
        private javax.swing.JPasswordField mp;
        // End of variables declaration
     
    }
    et voici les codes erreurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Compiling 1 source file to F:\Documents and Settings\Administrateur\Bureau\monprojet\build\classes
    F:\Documents and Settings\Administrateur\Bureau\monprojet\src\monprojet\Connexion.java:24: cannot find symbol
    symbol  : class ActionListener
    location: class monprojet.Connexion
            inscription.addActionListener(new ActionListener());
    F:\Documents and Settings\Administrateur\Bureau\monprojet\src\monprojet\Connexion.java:140: non-static method setVisible(boolean) cannot be referenced from a static context
          employe.setVisible(true);
    2 errors
    BUILD FAILED (total time: 0 seconds)
    encore merci à ceux qui m'aide!!
    bonne soirée
    krikri

  6. #6
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Bonsoir,

    ActionListener est une interface, tu ne peux pas faire instancier un objet à partir d'une interface sans proposer une implémentation de celle ci dans une inner class.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    addActionListener(new ActionListsner() {
      public void actionperformed(ActionEvent e) {
         //l'action à réaliser 
      }
    });
    Puis dans ta méthode inscriptionActionPerformed tu devrais plutôt appeler la méthode setVisible sur l'instance de l'objet employe que tu as créé (à savoir toto) que sur la classe elle même vu que setVisble n'est pas une méthode statique.


    Petit apparté, si tu pouvais respecter les conventions de codage (une majuscule au nom de classe, c'est à dire Employe au lieu d'employe) et éviter de mettre le code de layout de netbeans (qui est imbuvable et pas prévu pour être lu par des humains) dans ce que tu nous fournis, ce serait quand même vachement plus simple à lire et pour nous de détecter l'erreur.
    @+

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 25
    Par défaut
    Merci mille fois!! mais maintenant j'aurais une autre petite question!!!
    comment faire pour que quand la nouvelle fenetre s'ouvre l'autre se ferme!!!??
    Pour ce qui est des regles je les savais mais je n'ai pas fais gaffe!!! Désolé maintenant je vais en tenir compte!!
    Encore merci et si vous pouviez me repondre à cette nouvelle question ca serait encore mieux!!
    bonne soirée
    krikri

Discussions similaires

  1. [Java/Java'scool][Swing] Ouvrir une JFrame avec un bouton
    Par El Kun dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 13/05/2014, 09h16
  2. Ouvrir une JFrame sur le second écran
    Par nassima_1418 dans le forum Agents de placement/Fenêtres
    Réponses: 9
    Dernier message: 22/10/2013, 11h31
  3. ouvrir un jframe avec un jbutton sur une autre jframe.
    Par argon dans le forum Agents de placement/Fenêtres
    Réponses: 11
    Dernier message: 07/05/2007, 19h23
  4. Ouvrir une JFrame à partir d'une autre
    Par seyar666 dans le forum Agents de placement/Fenêtres
    Réponses: 6
    Dernier message: 09/03/2007, 15h53
  5. [NetBeans] [Débutant] Ouvrir une JFrame[NetBeans 4.1]
    Par Terminator dans le forum NetBeans
    Réponses: 1
    Dernier message: 19/09/2005, 14h39

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