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
|
public class Manipcompte extends JFrame implements ActionListener {
/* initialisation des propriétés du compte */
String Type_cpt = "Courant";
String Num_cpt = "";
private JLabel imgFond;
private JLabel label_Euros;
private JLabel label_Solde;
private ImageIcon img_IHMFond;
private JPanel saisie_Lignes;
private ButtonGroup boutonsGrp;
private JCheckBox courant;
private JCheckBox entreprise;
private JTextField val_Saisie;
private JButton btn_OK;
public Manipcompte (String cpt) {
initComposants();
/* affichage dans le cadre de l'interface le type, le numéro et le solde du compte en question */
Border cadre = BorderFactory.createTitledBorder("Compte n ° : " + cpt + " ");
saisie_Lignes.setBorder(cadre);
this.setBounds(500, 130, 470, 390);
this.setVisible(true);
/* chargement et placement de l'image de fond de l'interface */
img_IHMFond = new ImageIcon("Images/FondCompte.png");
imgFond.setIcon(img_IHMFond);
boutonsBox();
Num_cpt = cpt;
}
/*
* méthode pour créer les boutons de selection pour le type de compte
*/
private void boutonsBox() {
boutonsGrp.add(courant);
boutonsGrp.add(entreprise);
/* sélection du type courant par defaut */
courant.setSelected(true);
}
/**
* méthode pour initialiser tous les composants graphisue de l'interface
*/
private void initComposants() {
boutonsGrp = new ButtonGroup();
courant = new JCheckBox();
entreprise = new JCheckBox();
saisie_Lignes = new JPanel();
val_Saisie = new JTextField();
btn_OK = new JButton();
label_Euros = new JLabel();
label_Solde = new JLabel();
imgFond = new JLabel();
/* rendre possible la fermeture de l'interface par la croix en haut a droite */
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setTitle("Créer un compte");
/* définition de la couleur de fond */
this.setBackground(new Color(190, 190, 190));
/* rendre le fenêtre non redimensionnable */
this.setResizable(false);
saisie_Lignes.setBorder(BorderFactory.createTitledBorder(" Comptes "));
courant.setText("Compte Courant");
courant.addActionListener(this);
entreprise.setText("Compte Entreprise");
entreprise.addActionListener(this);
val_Saisie.setHorizontalAlignment(JTextField.RIGHT);
val_Saisie.setText("0");
btn_OK.setText("OK");
btn_OK.addActionListener(this);
label_Euros.setText("Euros");
label_Solde.setText("Solde :");
GroupLayout gl = new GroupLayout(saisie_Lignes);
saisie_Lignes.setLayout(gl);
gl.setHorizontalGroup(
gl.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl.createSequentialGroup().addContainerGap()
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
.addGroup(gl.createSequentialGroup()
.addComponent(label_Solde)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(val_Saisie, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(label_Euros)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_OK))
.addGroup(gl.createSequentialGroup()
.addComponent(courant)
.addGap(40, 40, 40)
.addComponent(entreprise)))
.addContainerGap(36, Short.MAX_VALUE))
);
gl.setVerticalGroup(
gl.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl.createSequentialGroup().addContainerGap()
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(courant)
.addComponent(entreprise))
.addGap(37, 37, 37)
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(label_Solde)
.addComponent(label_Euros)
.addComponent(val_Saisie, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btn_OK))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
imgFond.setText("JLabel1");
GroupLayout gl2 = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(gl2);
gl2.setHorizontalGroup(gl2.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl2.createSequentialGroup()
.addGroup(gl2.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl2.createSequentialGroup().addGap(145, 145, 145)
.addComponent(imgFond))
.addGroup(gl2.createSequentialGroup().addContainerGap()
.addComponent(saisie_Lignes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(914, Short.MAX_VALUE))
);
gl2.setVerticalGroup(gl2.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(gl2.createSequentialGroup()
.addContainerGap()
.addComponent(saisie_Lignes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(imgFond)
.addContainerGap(914, Short.MAX_VALUE))
);
this.pack();
}
/**
* méthode gérant les évènements sur les éléments graphiques
* @param btn l'élément en question
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn_OK) {
/* récupération de la valeur de départ du montant à l'ouverture du compte */
double val_Init = Double.parseDouble(val_Saisie.getText());
/* création d'un compte */
CompteBancaires cb = new CompteBancaires(Num_cpt, Type_cpt, val_Init);
/* enregistrement du compte dans un fichier objet (.dat) */
cb.affichage();
/* création du fichier */
Lect_Sauv_comptebancaires fichier = new Lect_Sauv_comptebancaires();
/* ouverture du fichier en mode ecriture */
fichier.ouvrirFichier("Comptes/"+Num_cpt+".dat", "W");
/* enregistrement du compte dans le fichier */
fichier.ecrireFichier(cb);
/* fermeture du fichier */
fichier.fermerFichier();
/* pour fermer la fenêtre sans quitter l'application */
this.dispose();
}
if (e.getSource() == entreprise) {
/* type de compte "Entreprise" */
Type_cpt = "Entreprise";
}
if (e.getSource() == courant) {
/* type de compte "Entreprise" */
Type_cpt = "Courant";
}
}
} |
Partager