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
|
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.io.* ;
import java.util.*;
class client implements Serializable{
String nom,prenom,adresse;
public client(String nom,String prenom,String adresse){
this.nom=nom;
this.prenom=prenom;
this.adresse=adresse;
}
}
//---------------------------------------------------
class compte implements Serializable {
int numero_compte,solde, mot_passe;
client cl;
Vector v=new Vector();
public compte(int numero_compte,int solde, int mot_passe,client cl){
this.numero_compte= numero_compte;
this.solde=solde;
this.mot_passe=mot_passe;
this.cl=cl;
}
public void retirer(int r){
solde=solde-r;
}
public void deposer(int d){
solde =solde+d;
}
}
public class banque extends JFrame implements ActionListener
{
JButton bvalider=new JButton("Valider");
JLabel lnom=new JLabel("Nom");
JLabel lprenom=new JLabel("Prenom");
JLabel ladresse=new JLabel("Adresse");
JLabel lsolde=new JLabel("Solde");
JLabel lnum=new JLabel("Numero compte");
JLabel lpasse=new JLabel("Mot de passe");
JTextField tnom =new JTextField(20);
JTextField tprenom =new JTextField(20);
JTextField tadresse =new JTextField(40);
JTextField tsolde =new JTextField(10);
JTextField tnum =new JTextField(10);
JPasswordField tpasse =new JPasswordField(10);
//Vector v=new Vector();
public banque()
{
super("welcome to our bank");
//v=null;
//v=Lire();
//System.out.println(""+v.size());
setSize(800,800);
setVisible(true);
JPanel pane =new JPanel();
//100
pane.setLayout(null);
setContentPane(pane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pane.add(lnom).setBounds(100,150,100,35);
pane.add(lprenom).setBounds(100,200,100,35);
pane.add(ladresse).setBounds(100,250,100,35);
pane.add(lsolde).setBounds(100,300,100,35);
pane.add(lnum).setBounds(100,350,100,35);
pane.add(lpasse).setBounds(100,400,100,35);
pane.add(tnom).setBounds(300,150,100,35);
pane.add(tprenom).setBounds(300,200,100,35);
pane.add(tadresse).setBounds(300,250,100,35);
pane.add(tsolde).setBounds(300,300,100,35);
pane.add(tnum).setBounds(300,350,100,35);
pane.add(tpasse).setBounds(300,400,100,35);
pane.add(bvalider).setBounds(100,500,100,35);
bvalider.addActionListener(this);
repaint();
}
public void actionPerformed(ActionEvent e)
{
Object source =e.getSource();
if(source==bvalider)
{
//try
//{
Vector v=new Vector();
v=Lire();
client cl=new client (tnom.getText(),tprenom.getText(),tadresse.getText());
int num= Integer.parseInt(tnum.getText());
int solde= Integer.parseInt(tsolde.getText());
int passe= Integer.parseInt(tpasse.getText());
compte c=new compte(num,solde,passe,cl);
//System.out.println(""+v.size());
//203
/*
int j;
boolean trouve=false;
for(int i=0;i<v.size();i++){
compte compt=(compte) v.elementAt(i);
client cli1=(client) compt.cl;
if(num==compt.numero_compte && passe==compt.mot_passe){
trouve=true;
System.out.println("attention");
j=i;
}}*/
v.addElement(c);
System.out.println(""+v.size());
Ecrire(v);
/*
}
catch (IOException ee)
{ee.printStackTrace();}
finally {
try
{fich.close();}
catch (IOException zz)
{zz.printStackTrace();}
}*/
tnom.setText(" ");
tprenom.setText(" ");
tadresse.setText(" ");
tsolde.setText(" ");
tnum.setText(" ");
tpasse.setText("");
}
}
void Ecrire (Vector v)
{
try {
FileOutputStream file = new FileOutputStream ("personnes.txt") ;
ObjectOutputStream out = new ObjectOutputStream (file) ;
out.writeObject (v) ;
out.flush () ;
out.close () ;
} catch (IOException ex)
{
System.err.println ("Erreur d'ecriture " + ex) ;
}
}
Vector Lire ()
{
Vector v= null ;
try {
FileInputStream file = new FileInputStream("personnes.txt") ;
ObjectInputStream in = new ObjectInputStream (file) ;
v = (Vector) in.readObject() ;
in.close();
} catch (Exception ex)
{
System.err.println ("Erreur de lecture " + ex) ;
}
return v;
}
public static void main(String[] s)
{
banque f=new banque() ;
}
} |
Partager