JMenuBar : creer sa propre classe pour la gestion des menus : problème.
bonjour,
je souhaite creer une classe qui gère les menu de mon application.
Pour cela, j'ai créé la classe MenuBarLims extends JMenuBar dans laquelle j'ai défini mes menu ds le constructeur. Puis dans laclasse gérant l'application je fais :
Code:
1 2
| MenuBarLims menuBarlims = new MenuBarLims() ;
frame.setJMenuBar(menuBarlims); |
mais cela ne fonctionne pas ...
est ce que quelqu'un à une idée d'ou peut venir le problème ??
merci d'avance,
voici le code :
classe MenuBarLims extends JMenuBar :
Code:
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
| package application;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class MenuBarLims extends JMenuBar {
JMenuBar menuBar;
public MenuBarLims () {
menuBar = new JMenuBar();
JMenu menuOrder = new JMenu("Order");
menuOrder.setMnemonic(KeyEvent.VK_O);
menuBar.add(menuOrder);
JMenu menuCustomer = new JMenu("Customer");
menuCustomer.setMnemonic(KeyEvent.VK_C);
menuBar.add(menuCustomer);
JMenu menuAnalysis = new JMenu("Analysis");
menuAnalysis.setMnemonic(KeyEvent.VK_A);
menuBar.add(menuAnalysis);
JMenu menuBill = new JMenu("Bill");
menuBill.setMnemonic(KeyEvent.VK_B);
menuBar.add(menuBill);
JMenu menuUser = new JMenu("Users");
menuUser.setMnemonic(KeyEvent.VK_U);
menuBar.add(menuUser);
JMenu menuBatch = new JMenu("Batch");
menuBatch.setMnemonic(KeyEvent.VK_T);
menuBar.add(menuBatch);
menuBar.setVisible(true);
}
} |
et classe de l'application :
Code:
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
| package application;
import imageBackground.BackgroundPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
public class Application {
/************************************************************************************/
Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
int height = (int)tailleEcran.getHeight();
int width = (int)tailleEcran.getWidth();
//taille fenetre globale (avec le background)
float height_fenetre = height * (float)(0.70) ;
float width_fenetre = width* (float)(0.40) ;
//taille de la partie de l application (pas le background)
float height_apps = ((float)0.80 * height_fenetre);
float width_apps = ((float)0.90 * width_fenetre);
//centrage
float bound_height =( height_fenetre - height_apps)/2 ;
float bound_width =( width_fenetre - width_apps)/2 ;
/************************************************************************************/
private JPanel pBackground;
public Application () {
JFrame frame= new JFrame();
Container contenu = frame.getContentPane();
//backgrouund
pBackground = new BackgroundPanel(getClass().getResource("21.jpg"));
pBackground.setLayout(null);// pour pouvoir utilier setBounds
contenu.add(pBackground);
//panneau de l application : pApplication
JPanel pApplication = new JPanel();
pBackground.add(pApplication);
pApplication.setBounds((int) bound_width, (int)bound_height, (int)width_apps, (int)height_apps);
pApplication.setBackground(Color.cyan);
pApplication.setLayout(new BorderLayout());
MenuBarLims menuBarlims = new MenuBarLims() ;
frame.setJMenuBar(menuBarlims);
/************************************************************************************/
frame.setTitle("GenIndex LIMS");
frame.setBounds( width/5, height/5, (int) width_fenetre, (int) height_fenetre);
//frame.setResizable(false);
frame.setVisible(true);
}
}// |
merci d'avance,
benilto