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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class UniqueInternalFrameDemo extends JFrame
implements InternalFrameListener,
ActionListener
{
JDesktopPane jdp = new JDesktopPane();
JInternalFrame fenetreUnique;
JLabel info = new JLabel(" ");
public UniqueInternalFrameDemo(String title)
{
super(title);
//Set up the GUI.
Container cont = getContentPane();
JButton bout = new JButton("Afficher la 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) {
fenetreUnique.setVisible(false);
info.setText("On a caché la fenêtre");
}
public void internalFrameOpened(InternalFrameEvent e) {
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
public void internalFrameActivated(InternalFrameEvent e) {
}
public void internalFrameDeactivated(InternalFrameEvent e) {
}
public void actionPerformed(ActionEvent e)
{
System.out.println("Clic sur bouton");
if (fenetreUnique == null)
{
fenetreUnique = new JInternalFrame("Fiche Client",
true, //resizable
true, //closable
true, //maximizable
true); //iconifiable
fenetreUnique.addInternalFrameListener(this);
fenetreUnique.setSize(200, 150);
jdp.add(fenetreUnique);
fenetreUnique.setVisible(true);
info.setText("On crée la fenêtre");
}
else {
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
* event-dispatching thread.
*/
private static void createAndShowGUI()
{
//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()
{
createAndShowGUI();
}
});
}
} |
Partager