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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class UniqueInternalFrameDemo extends JFrame
implements InternalFrameListener,
ActionListener
{
JLabel info = new JLabel(" ");
JDesktopPane jdp = new JDesktopPane();
JInternalFrame fenetreUnique;
public UniqueInternalFrameDemo(String title)
{
super(title);
// on place l'interface graphique
Container cont = getContentPane();
JButton bout = new JButton("Afficher l'unique JInternalFrame");
bout.addActionListener(this);
cont.add(bout, BorderLayout.NORTH);
jdp.putClientProperty("JDesktopPane.dragMode", "outline");
cont.add(jdp, BorderLayout.CENTER);
cont.add(info, BorderLayout.SOUTH);
setVisible(true);
}
public void internalFrameClosing(InternalFrameEvent e) {
}
public void internalFrameClosed(InternalFrameEvent e) {
}
public void internalFrameOpened(InternalFrameEvent e) {
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
public void internalFrameActivated(InternalFrameEvent e) {
info.setText("On a activé la fenêtre");
}
public void internalFrameDeactivated(InternalFrameEvent e) {
info.setText("On a désactivé la fenêtre");
}
public void actionPerformed(ActionEvent e)
{
System.out.println("Clic sur bouton");
// si la JInternalFrame n'existe pas encore :
if (fenetreUnique == null)
{
fenetreUnique = new JInternalFrame("Fiche Client",
true, // on peut changer la taille
true, // on peut la fermer
true, // on peut la maximiser
true); // on peut l'iconifier
fenetreUnique.addInternalFrameListener(this);
JTextField champTexte = new JTextField();
JLabel bidon1 = new JLabel(" ");
JLabel bidon2 = new JLabel(" ");
Container co = fenetreUnique.getContentPane();
co.add( bidon1, BorderLayout.NORTH );
co.add(champTexte, BorderLayout.CENTER);
co.add( bidon2, BorderLayout.SOUTH );
fenetreUnique.setSize(200, 100);
fenetreUnique.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
jdp.add(fenetreUnique);
fenetreUnique.setVisible(true);
info.setText("On crée la fenêtre");
}
else // si elle existe :
{
fenetreUnique.setVisible(true);
info.setText("On ré-affiche la fenêtre");
}
}
// Create the GUI and show it. For thread safety,
// this method should be invoked from the
// eventdispatching thread.
private static void creationDeLInterface()
{
//Create and set up the window.
JFrame frame = new UniqueInternalFrameDemo("Unique JInternalFrame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setSize(700, 500);
frame.setVisible(true);
}
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e) { }
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run()
{
creationDeLInterface();
}
});
}
} |
Partager