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.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;
private Action actionConfigMenus;
private Action actionCommentFaire;
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();
actionConfigMenus = new ActionConfigMenus();
actionCommentFaire = new ActionCommentFaire();
JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons);
JMenuItem itemConfigMenus = new JMenuItem(actionConfigMenus);
JMenuItem itemCommentFaire = new JMenuItem(actionCommentFaire);
menuAide.add (itemConfigMenus);
menuAide.add ( itemCommentFaire );
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
// ****** 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 ) {
// TODO Auto-generated method stub
}
}
private class ActionConfigMenus extends AbstractAction {
public ActionConfigMenus() {
super("Configuration des menus");
}
@ Override
public void actionPerformed ( ActionEvent e ) {
// TODO Auto-generated method stub
}
}
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;
}
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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);
}
}