Newer
Older
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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.AbstractAction;
import javax.swing.Action;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import edu.mermet.tp8.fenetres.FenetreBoutons;
import edu.mermet.tp8.fenetres.FenetreConversion;
import edu.mermet.tp8.fenetres.FenetreDiaporama;
import edu.mermet.tp8.fenetres.FenetreTexte;
/**
*
* @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;
public Application() {
super("multi-fenêtres");
this.setContentPane(new JDesktopPane());
// ****** 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();
JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons);
menuApplication.add(itemBoutons);
barre.add(menuApplication);
// ****** 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);
}
}
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 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 static void main(String[] args) {
SwingUtilities.invokeLater(Application::new);
}
}