JMenuItem

Résolu
theo557 Messages postés 17 Date d'inscription mardi 24 octobre 2006 Statut Membre Dernière intervention 11 mars 2008 - 15 nov. 2006 à 22:17
didoux95 Messages postés 845 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 1 août 2017 - 21 nov. 2006 à 19:10
Bonjour,
voila je suis entrain de commencer a programme un programme de gestion de personnel.
Voila j'ai créé mes interfaces graphique avec NetBeans 5 (pour le moment au nombre de 2 classes)
donc mon problem dans la premiere classe j'ai mis un JMenuBar "Fichier" avec des  JMenuItem "Nouveau".
se que je voudrais faire c'est que quand je clique sur Nouveau il m'ouvre la fenetre de la deuxieme classe.
Si une personne a la réponse merci d'avance.
 

7 réponses

didoux95 Messages postés 845 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 1 août 2017 2
21 nov. 2006 à 19:10
Slt
si la reponse te convient reelement, alors valide-la.
merci +
3
didoux95 Messages postés 845 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 1 août 2017 2
16 nov. 2006 à 11:01
slt
Tu creer un ActionListener pour ce composant est tu lui dis de faire "new MaSecondeClass();"

JMenuItem CmdNouveau = new JMenuItem("Nouveau");
CmdNouveau.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent evt){
      new MaSecondeClass();
   }
});

Je pense cela repond a ta question.
Voila+
0
theo557 Messages postés 17 Date d'inscription mardi 24 octobre 2006 Statut Membre Dernière intervention 11 mars 2008
16 nov. 2006 à 22:39
marche pas voici le code d ma classe:

/*
 * acceuille.java
 *
 * Created on 13 novembre 2006, 14:51
 */


package houilles;
import java.awt.*;
import javax.swing.JFrame;
import houilles.Newp;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;


public class acceuille extends javax.swing.JFrame {


    public acceuille() {
        initComponents();
       
    }
   
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        Menu1 = new javax.swing.JMenuBar();
        Fichier = new javax.swing.JMenu();
        Nouveau = new javax.swing.JMenuItem();
        Recherche = new javax.swing.JMenuItem();
        Effacer = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        Cartonacces = new javax.swing.JMenuItem();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setBackground(new java.awt.Color(102, 153, 255));
        jLabel1.setFont(new java.awt.Font("Bodoni MT Condensed", 0, 36));
        jLabel1.setText("GESTION DE LA BASE DE DONNEES DU C.C.MILLE");


        Fichier.setText("Fichiers");
        Nouveau.setText("Nouveau");
        Nouveau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Nouveau(evt);
            }
        });


        Fichier.add(Nouveau);


        Recherche.setText("Recherche");
        Fichier.add(Recherche);


        Effacer.setText("Effacer");
        Fichier.add(Effacer);


        Menu1.add(Fichier);


        jMenu2.setText("Imprimer");
        Cartonacces.setText("Carton d'acc\u00e9s");
        jMenu2.add(Cartonacces);


        Menu1.add(jMenu2);


        setJMenuBar(Menu1);


        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(84, Short.MAX_VALUE)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 558, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(135, 135, 135)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 224, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(335, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>                       




    private void Nouveau(java.awt.event.ActionEvent evt) {                        


 


      
 


 


    }                       


    


          
           
      
   
   
    // Variables declaration - do not modify                    
    private javax.swing.JMenuItem Cartonacces;
    private javax.swing.JMenuItem Effacer;
    private javax.swing.JMenu Fichier;
    private javax.swing.JMenuBar Menu1;
    private javax.swing.JMenuItem Nouveau;
    private javax.swing.JMenuItem Recherche;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu2;
    // End of variables declaration                  




}

je n'y arrive pas
0
kaloway Messages postés 358 Date d'inscription jeudi 24 octobre 2002 Statut Membre Dernière intervention 13 avril 2020
18 nov. 2006 à 11:12
ça doit marcher mais tu vois rien. car ta méthode Nouveau ne fait rien.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
theo557 Messages postés 17 Date d'inscription mardi 24 octobre 2006 Statut Membre Dernière intervention 11 mars 2008
18 nov. 2006 à 21:25
Alors comment faire pour afficher cette deuxieme classe JFrame rien quand cliquant sur "fichier" et "Nouveau"
merci pour l'aide que vous m'apportez
0
didoux95 Messages postés 845 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 1 août 2017 2
18 nov. 2006 à 22:11
Slt
tu fais une methode "main"
public static void main(String arg[]){
   new acceuille().setVisible(tru);
}

voila, je pense que cela devrais marcher. +
0
theo557 Messages postés 17 Date d'inscription mardi 24 octobre 2006 Statut Membre Dernière intervention 11 mars 2008
20 nov. 2006 à 15:20
Merci


ça marche
0
Rejoignez-nous