Comment faire une action dans le JMenuItem ?

Fermé
westerndigit Messages postés 134 Date d'inscription mercredi 16 février 2011 Statut Membre Dernière intervention 18 avril 2012 - 9 janv. 2012 à 07:26
westerndigit Messages postés 134 Date d'inscription mercredi 16 février 2011 Statut Membre Dernière intervention 18 avril 2012 - 9 janv. 2012 à 11:16
Bonjour,


Comment faire pour que lorsque je clique sur menu fichier "montant ht en ttc" cela ouvre le code concerné

Faut il utiliser un Action Listener ?

Merci,

voici mon code :

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* Menus.java
*
* Created on 9 janv. 2012, 04:08:38
*/
package formulaire;

/**
*
* @author
*/
public class Menus extends javax.swing.JFrame {

/** Creates new form Menus */
public Menus() {
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() {

jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jMenu1.setBackground(new java.awt.Color(0, 204, 204));
jMenu1.setText("Fichier");

jMenuItem1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Bernard\\Mes documents\\Mes images\\48px-Crystal_Clear_app_vcalendar.png")); // NOI18N
jMenuItem1.setText("Montant HT en TTC");
jMenu1.add(jMenuItem1);

jMenuItem2.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Bernard\\Mes documents\\Mes images\\48px-Crystal_Clear_app_vcalendar.png")); // NOI18N
jMenuItem2.setText("Montant TTC en HT");
jMenu1.add(jMenuItem2);

jMenuItem3.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Bernard\\Mes documents\\Mes images\\48px-Crystal_Clear_action_button_cancel.png")); // NOI18N
jMenuItem3.setText("Quitter");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);

jMenuBar1.add(jMenu1);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 279, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Menus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Menus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Menus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Menus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new Menus().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
// End of variables declaration
}

2 réponses

choubaka Messages postés 39394 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 1 juin 2024 2 101
Modifié par choubaka le 9/01/2012 à 07:56
Bonjour

voici un petit tuto pour t'aider

http://www.javafr.com/codes/TUTORIEL-CREATION-JMENU-LIENS_15589.aspx

ici dessous, plus complet mais en anglais

https://docs.oracle.com/javase/tutorial/uiswing/components/menu.html


Chouba, Modérateur CCM
Bibapeloula
0
westerndigit Messages postés 134 Date d'inscription mercredi 16 février 2011 Statut Membre Dernière intervention 18 avril 2012
9 janv. 2012 à 11:16
je comprends pas dans mon cas que faire ???

simple pour certain mais du chinois pour moi

j'ai l'impression que java est difficile à expliquer je ne me trompe pas

Quand on le connait il est difficile de l'expliquer.

Moi je suis passé par le mode design ensuite je rajoute mes codes

Ce que je veux c'est cliquer sur un des montants et ouvrir une application java c'est tout simple oui mais moi je n'y arrive pas
0