Newer
Older
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 {

Yann Reibel
a validé
private JInternalFrame conversion;
private JInternalFrame texte;
private JInternalFrame diaporama;
private JInternalFrame boutons;

Yann Reibel
a validé
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;

Yann Reibel
a validé
private String utilisateur;
public Application(String utilisateur) {
super("multi-fenêtres");
this.setContentPane(new JDesktopPane());

Yann Reibel
a validé
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");
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);
menuAide.add(itemAideConversion);
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
// ****** 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;
}
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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;
}

Yann Reibel
a validé
public String getUtilisateur(){
return this.utilisateur;
}

Yann Reibel
a validé
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);
});