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
|
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/*
* Créé le 11 juil. 07
*
* Pour changer le modèle de ce fichier généré, allez à :
* Fenêtre>Préférences>Java>Génération de code>Code et commentaires
*/
/**
* @author secabane
*
* Pour changer le modèle de ce commentaire de type généré, allez à :
* Fenêtre>Préférences>Java>Génération de code>Code et commentaires
*/
public class FrameController {
private JFrame mainFrame;
private JFrame f1,f2,f3;
public FrameController() {
mainFrame = new JFrame();
mainFrame.addWindowListener(new WindowAdapter() {
/* (non-Javadoc)
* @see java.awt.event.WindowAdapter#windowClosed(java.awt.event.WindowEvent)
*/
public void windowClosing(WindowEvent arg0) {
quit();
}
});
JButton action1 = new JButton("afficher/fermer frame 1");
action1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
toggleF1Visibility();
}
});
JButton action2 = new JButton("afficher/fermer frame 2");
action2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
toggleF2Visibility();
}
});
JButton action3 = new JButton("afficher/fermer frame 3");
action3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
toggleF3Visibility();
}
});
mainFrame.add(action1,BorderLayout.NORTH);
mainFrame.add(action2,BorderLayout.CENTER);
mainFrame.add(action3,BorderLayout.SOUTH);
f1 = new JFrame("Frame 1");
f1.setSize(100,75);
f1.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
f2 = new JFrame("Frame 2");
f2.setSize(100,75);
f2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
f3 = new JFrame("Frame 3");
f3.setSize(100,75);
f3.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
});
}
public void quit() {
mainFrame.dispose();
f1.dispose();
f2.dispose();
f3.dispose();
//....
}
public void toggleF1Visibility() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f1.setVisible(! f1.isVisible());
}
});
}
public void toggleF2Visibility() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f2.setVisible(! f2.isVisible());
}});
}
public void toggleF3Visibility() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f3.setVisible(! f3.isVisible());}});
}
public void showF1() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f1.setVisible(true);
}});
}
public void hideF1() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f1.setVisible(false);
}});
}
public void showF2() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f2.setVisible(true);
}});
}
public void hideF2() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f2.setVisible(false);
}});
}
public void showF3() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f3.setVisible(true);
}});
}
public void hideF3() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
f3.setVisible(false);
}});
}
public static void main(String[] args) {
FrameController c = new FrameController();
}
} |
Partager