package edu.mermet.tp8; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import javax.swing.*; import edu.mermet.tp8.fenetres.FenetreBoutons; import edu.mermet.tp8.fenetres.FenetreConversion; import edu.mermet.tp8.fenetres.FenetreDiaporama; import edu.mermet.tp8.fenetres.FenetreTexte; import edu.mermet.tp8.fenetres.modales.CommentFaireDialogue; import edu.mermet.tp8.fenetres.modales.ConfigurationMenusDialogue ; /** * * @author brunomermet */ public class Application extends JFrame { private JInternalFrame conversion; private JInternalFrame texte; private JInternalFrame diaporama; private JInternalFrame boutons; private Action actionAfficherConversion; private Action actionAfficherTexte; private Action actionAfficherDiaporama; private Action actionAfficherBoutons; private Action actionConfigMenus; private Action actionCommentFaire; private Action actionAideConversion; //private Frame frame = this; private Application frameApp = this; private String utilisateur; public Application(String utilisateur) { super("multi-fenêtres"); this.setContentPane(new JDesktopPane()); this.utilisateur = utilisateur; // ****** Barre de menu ****** JMenuBar barre = new JMenuBar(); // ------ menu Fichier ------ JMenu menuFichier = new JMenu("Fichier"); menuFichier.setMnemonic(KeyEvent.VK_F); JMenuItem quitter = new JMenuItem("Quitter"); quitter.addActionListener (new ActionListener() { @Override public void actionPerformed(ActionEvent aev) { System.exit(0); } }); quitter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); menuFichier.add(quitter); barre.add(menuFichier); this.setJMenuBar(barre); // ------ menu Applications ------ JMenu menuApplication = new JMenu("Applications"); JMenu menuAide = new JMenu("Aide"); menuApplication.setMnemonic(KeyEvent.VK_A); actionAfficherConversion = new ActionAfficherConversion(); JMenuItem itemConversion = new JMenuItem(actionAfficherConversion); menuApplication.add(itemConversion); actionAfficherTexte = new ActionAfficherTexte(); JMenuItem itemTexte = new JMenuItem(actionAfficherTexte); menuApplication.add(itemTexte); actionAfficherDiaporama = new ActionAfficherDiaporama(); JMenuItem itemDiaporama = new JMenuItem(actionAfficherDiaporama); menuApplication.add(itemDiaporama); actionAfficherBoutons = new ActionAfficherBoutons(); actionConfigMenus = new ActionConfigMenus(); actionCommentFaire = new ActionCommentFaire(); actionAideConversion = new ActionAideConversion(); JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons); JMenuItem itemConfigMenus = new JMenuItem(actionConfigMenus); JMenuItem itemCommentFaire = new JMenuItem(actionCommentFaire); JMenuItem itemAideConversion = new JMenuItem(actionAideConversion); menuApplication.add(itemBoutons); menuAide.add (itemConfigMenus); menuAide.add (itemCommentFaire); menuAide.add(itemAideConversion); barre.add(menuApplication); barre.add(menuAide); // ****** Fin barre de menu ****** // ****** Création des fenêtres ****** // ------ fenêtre conversion ------ conversion = new FenetreConversion(actionAfficherConversion); this.add(conversion); // ------ fenêtre texte ------ texte = new FenetreTexte(actionAfficherTexte); this.add(texte); // ------ fenêtre diaporama ------ diaporama = new FenetreDiaporama(actionAfficherDiaporama); this.add(diaporama); // ------ fenêtre boutons ------ boutons = new FenetreBoutons(this,actionAfficherBoutons); this.add(boutons); // ****** Fin création fenêtres ****** setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(600,300); this.setLocationRelativeTo(null); setVisible(true); } private class ActionAfficherBoutons extends AbstractAction { public ActionAfficherBoutons() { super("Boutons"); putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK)); putValue(Action.MNEMONIC_KEY,KeyEvent.VK_B); } @Override public void actionPerformed(ActionEvent ae) { boutons.setVisible(true); enableBoutons(false); } } private class ActionAfficherDiaporama extends AbstractAction { public ActionAfficherDiaporama() { super("Diaporama"); putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); putValue(Action.MNEMONIC_KEY,KeyEvent.VK_D); } @Override public void actionPerformed(ActionEvent ae) { diaporama.setVisible(true); enableDiaporama(false); } } private class ActionAfficherTexte extends AbstractAction { public ActionAfficherTexte() { super("Saisie de texte"); putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK)); putValue(Action.MNEMONIC_KEY,KeyEvent.VK_T); } @Override public void actionPerformed(ActionEvent ae) { texte.setVisible(true); enableTexte(false); } } private class ActionCommentFaire extends AbstractAction { public ActionCommentFaire() { super("Comment faire ?"); } @ Override public void actionPerformed ( ActionEvent e ) { new CommentFaireDialogue(frameApp); } } private class ActionConfigMenus extends AbstractAction { public ActionConfigMenus() { super("Configuration des menus"); } @ Override public void actionPerformed ( ActionEvent e ) { new ConfigurationMenusDialogue(frameApp); } } private class ActionAideConversion extends AbstractAction{ String message; public ActionAideConversion() { super("Aide conversion degrés"); message="Fenetre de conversion de degrés \n \n" + "Premier champ : saisie d'une valeur en degré Celsius \n" + "Second champ : saisie d'une valeur en degré Farenheit"; } @Override public void actionPerformed(ActionEvent ae) { JOptionPane aide = new JOptionPane(); aide.showMessageDialog(frameApp, message, "Aide", JOptionPane.INFORMATION_MESSAGE); } } public class ActionAfficherConversion extends AbstractAction { public ActionAfficherConversion() { super("Conversion Celsius/Farenheit"); putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK)); putValue(Action.MNEMONIC_KEY,KeyEvent.VK_C); } @Override public void actionPerformed(ActionEvent ae) { conversion.setVisible(true); enableConversion(false); } } public Action getActionCommentFaire() { return actionCommentFaire; } public Action getActionConfigMenus() { return actionConfigMenus; } public void enableConversion(boolean b) { actionAfficherConversion.setEnabled(b); } public void enableTexte(boolean b) { actionAfficherTexte.setEnabled(b); } public void enableDiaporama(boolean b) { actionAfficherDiaporama.setEnabled(b); } public void enableBoutons(boolean b) { actionAfficherBoutons.setEnabled(b); } public Action getActionAfficherConversion() { return actionAfficherConversion; } public Action getActionAfficherTexte() { return actionAfficherTexte; } public Action getActionAfficherDiaporama() { return actionAfficherDiaporama; } public String getUtilisateur(){ return this.utilisateur; } public static void main(String[] args) { String str; if(args.length > 0){ if(args[0] == null) str = System.getProperty("user.name"); else str = args[0]; } str = System.getProperty("user.name"); final String finalStr = str; SwingUtilities.invokeLater(() -> { new Application(finalStr); }); } }