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 184 185 186 187 188 189 190 191 192 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 227 228 229 230 231 232
|
import java.awt.*;
//utilisation de la bibliothèque graphique
import javax.swing.*;
//utilisation de la bibliothèque graphique
import javax.swing.event.*;
//utilisation de la programmation événementielle
//class Etiquette
class Etiquette extends JLabel
{
public Etiquette(String titre)
{
super(titre);
}
public Etiquette(String titre, Container c)
{
this(titre);
c.add(this);
}
}//Etiquette
//classe Entrée
class Entree extends JTextField
{
public Entree(String message)
{
super(message,15);
}
public Entree(String message, Container c)
{
this(message);
c.add(this);
}
/*public String contenu()
{
return this.getText();
}*/
}//Entree
//classe Sortie
class Sortie extends JTextField
{
public Sortie(String message)
{
super(message,15);
setEditable(false);
}
public Sortie(String message, Container c)
{
this(message);
c.add(this);
}
/*public void afficher(String texte)
{
this.setText(texte);
}*/
}//Sortie
//classe Bouton
class Bouton extends JButton
{
public Bouton(String libelle)
{
super(libelle);
setBackground(Color.gray);
}
public Bouton(String libelle, Container c)
{
this(libelle);
c.add(this);
}
}//Bouton
class Onglet extends JTabbedPane{
public Onglet()
{
super();
}
public void ajouteOnglet(String nom, JPanel p)
{
this.addTab(nom, p);
}
}
//classe Table
class Table extends JTable
{
public Table()
{
super();
}
}//Bouton
class Panneau extends JPanel
{
public Panneau()
{
super();
}
public Panneau(String titre)
{
super();
this.setBorder(BorderFactory.createTitledBorder(titre));
}
}
//classe Panneau
class PanneauOption extends JPanel
{
//déclaration de tous les composants utiliser pour ce panneau
Etiquette etiquetteCodeOption = new Etiquette("Code : ");
Etiquette etiquetteLibOption = new Etiquette("Libellé :");
Entree entreeCodeOption = new Entree("");
Entree entreeLibOption = new Entree("");
Bouton ajouter = new Bouton("ajouter");
Bouton suppr;
Table t = new Table();
Panneau p_edit = new Panneau("Edition des options");
Panneau p_tab = new Panneau("Liste des options");
private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
private Panneau PanneauEditOption()
{
p_edit.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
buildConstraints(c,0,0,1,2,0,0);
p_edit.add(etiquetteCodeOption, c);
buildConstraints(c,2,0,2,2,0,0);
p_edit.add(entreeCodeOption, c);
buildConstraints(c,0,3,1,2,0,0);
p_edit.add(etiquetteLibOption, c);
buildConstraints(c,2,3,2,2,0,0);
p_edit.add(entreeLibOption, c);
buildConstraints(c,5,1,2,2,0,0);
ajouter.setBackground(Color.GREEN);
p_edit.add(ajouter, c);
return p_edit;
}
public Panneau PanneauTabOption()
{
p_tab.setBorder(BorderFactory.createTitledBorder("Liste des options"));
p_tab.add(t);
suppr = new Bouton("Supprimer option sélectionnée", p_tab);
suppr.setBackground(Color.RED);
return p_tab;
}
public PanneauOption()
{
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
buildConstraints(c,0,0,1,1,0,0);
c.insets = new Insets(5, 5, 5, 5);
Panneau p_edit = PanneauEditOption();
Panneau p_tab = PanneauTabOption();
this.add(p_edit,c);
buildConstraints(c,0,1,1,1,0,0);
this.add(p_tab,c);
}
}
class MonCadre extends JFrame{
Onglet lesOnglets;
JPanel pannel = new JPanel();
PanneauOption pOption;
//fonction place()
private void place()//gère le positionnement et le dimensionnement du cadre
{
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();//dimension de l'écran
int he, le;//hauteur et largeur de l'écran
int hf, lf;//hauteur et largeur de la fenêtre
int Ox, Oy;//coordonnées du coin haut gauche de la fenêtre
he = (int)(d.getHeight());//recupère la hauteur de l'écran
le = (int)(d.getWidth());//récupère la largeur de l'écran
hf = he; lf = le;//la fenêtre prend 1/4 de l'écran
Ox = 0; Oy = 0;//placée à 1/4 du coin haut gauche
setLocation (Ox,Oy);//coordonnées du cadre en pixels
setSize(800,600);//dimensions du cadre en pixels
}
private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
//Constructeur Mon1Cadre
public MonCadre (String titre)
{
super(titre);
place();
//setLayout(new FlowLayout());
//setBackground(Color.green);//change la couleur du fond
JPanel panneau_princ = new JPanel();
panneau_princ.setLayout( new BorderLayout() );
//création des panneaux
pOption = new PanneauOption();
lesOnglets = new Onglet();
JPanel p_option = new JPanel() ;
JPanel onglet1 = new JPanel();
onglet1.add(pOption);
lesOnglets.ajouteOnglet("Gestion des options", onglet1);
panneau_princ.add(lesOnglets);
this.add(panneau_princ);
}
}//MonCadre
public class Projet {
public static void main (String [] arg)
{
MonCadre m;
m = new MonCadre("Portail des anciens élèves");//création du cadre
m.show();//le cadre est rendu visible
}//main
} |