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
|
public class InterfaceCompte extends JFrame implements ActionListener {
JFormattedTextField txtnumero,txtsolde,txtdecouvert,txtdate,txtcode;
JTextField txtnom,txtprenom;
JButton bvalider,banuler;
JCheckBox ch=new JCheckBox("Compte Cheque");
JLabel decouvre;
InterfaceCompte(){
this.setTitle("Creation d'un Compte");
this.setResizable(false);
this.setSize(350,500);
Container contenu = this.getContentPane();
JPanel paneau1 = new JPanel(new GridLayout(2,1));
JPanel paneau2 = new JPanel();
JPanel panHaut = new JPanel(new GridLayout(7,2));
//JPanel panBas = new JPanel(new GridLayout(3,2));
JPanel panBoutonHaut = new JPanel();
contenu.add(paneau1,BorderLayout.CENTER);
contenu.add(paneau2,BorderLayout.SOUTH);
paneau1.add(panHaut,BorderLayout.NORTH);
paneau1.add(panBoutonHaut,BorderLayout.SOUTH);
try {
MaskFormatter formata = new MaskFormatter("##########");
MaskFormatter formatb = new MaskFormatter("##/##/####");
MaskFormatter formatc = new MaskFormatter("AAA");
txtnumero = new JFormattedTextField(formata);
txtdate = new JFormattedTextField(formatb);
txtcode = new JFormattedTextField(formatc);
}
catch (java.text.ParseException exc) {
exc.printStackTrace();
}
NumberFormat format2 = NumberFormat.getInstance();
format2.setMinimumIntegerDigits(1);
txtnom = new JTextField("");
txtprenom = new JTextField("");
txtsolde = new JFormattedTextField(format2);
txtdecouvert = new JFormattedTextField(format2); txtdecouvert.setVisible(false);
bvalider = new JButton("Creer"); bvalider.addActionListener(this);
banuler = new JButton("Annuler"); banuler.addActionListener(this);
decouvre = new JLabel("Decouvert"); decouvre.setVisible(false);
panHaut.add(new JLabel("Code du client")); panHaut.add(txtcode);
panHaut.add(new JLabel("Prenom")); panHaut.add(txtprenom);
panHaut.add(new JLabel("Nom")); panHaut.add(txtnom);
panHaut.add(new JLabel("Date de Naissance(dd/mm/aaaa)")); panHaut.add(txtdate);
panHaut.add(new JLabel("Solde")); panHaut.add(txtsolde);
panHaut.add(new JLabel("Numero Compte")); panHaut.add(txtnumero);
panHaut.add(decouvre); panHaut.add(txtdecouvert);
ch.addActionListener(this);
panBoutonHaut.add(ch);// panBoutonHaut.add(type);
//panHaut.setBorder(new TitledBorder("Ouverture de Compte Personnel"));
Font f = new Font("Times New Roman",Font.ITALIC,12);
TitledBorder t = new TitledBorder(new LineBorder(Color.gray,1),"Ouverture de Compte Personnel",TitledBorder.LEFT, TitledBorder.TOP,f);
paneau1.setBorder(t);
Border b = BorderFactory.createLineBorder (Color.blue .darker ( ) ,5);
paneau2.setBorder(b);
paneau2.add(bvalider); paneau2.add(banuler);
//panBas.setBorder(new TitledBorder("Transaction sur le Solde"));
Font f2 = new Font("Times New Roman",Font.ITALIC,12);
TitledBorder t2 = new TitledBorder(new LineBorder(Color.gray,1),"Ouverture de Compte Personnel",TitledBorder.LEFT, TitledBorder.TOP,f2);
paneau2.setBorder(t2);
bvalider.addKeyListener(
new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode ();
if (code == KeyEvent.VK_ENTER){
InterfaceCompte.this.actionPerformed(new ActionEvent(e.getSource(),e.getID(),((JButton)e.getSource()).getActionCommand()));
}
}
}
);
// bcreer.setDefaultCapable(true);
banuler.addKeyListener(
new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode ();
if (code == KeyEvent.VK_ENTER){
InterfaceCompte.this.actionPerformed(new ActionEvent(e.getSource(),e.getID(),((JButton)e.getSource()).getActionCommand()));
}
}
}
);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==ch){
txtdecouvert.setVisible(true);
decouvre.setVisible(true);
}
if(ch.isSelected()==false){
txtdecouvert.setVisible(false);
decouvre.setVisible(false);
}
if(e.getSource()==banuler){
this.setVisible(false);
}
if(e.getSource()==bvalider){
//System.setSecurityManager(new RMISecurityManager());
Pattern motifLettres = Pattern.compile ("^[a-z;A-Z]+$");
if(txtcode.getValue()==null||txtprenom.getText().equals("")||txtnom.getText().equals("")||txtdate.getValue()==null||txtsolde.getValue()==null||txtnumero.getValue()==null)
JOptionPane.showMessageDialog (this,"Veuillez remplir tous les champs","Erreur remplissage",JOptionPane.INFORMATION_MESSAGE, null);
else {
if((ch.isSelected()!=false)&&(txtdecouvert.getValue()==null))
JOptionPane.showMessageDialog (this,"Veuillez remplir le champd decouvert!","Erreur remplissage",JOptionPane.INFORMATION_MESSAGE, null);
else{
if (! motifLettres.matcher (this.txtprenom.getText ()).matches ()||! motifLettres.matcher (this.txtnom.getText ()).matches ())
JOptionPane.showMessageDialog (this,"Les champs Nom,Prenom ne doivent contenir que des caracteres alphabetiques !","Erreur remplissage",JOptionPane.INFORMATION_MESSAGE, null);
else {
boolean b=false;
String c = txtcode.getText();
String p = txtprenom.getText();
String n = txtnom.getText();
String dt = (String)txtdate.getValue();
double s = (double)Double.parseDouble(""+txtsolde.getValue());
String num = (String)txtnumero.getValue();
if(ch.isSelected()==false){
double dc = 0;
try{
ICompte objet = (ICompte)Naming.lookup("rmi://192.168.1.108/obj");
b = objet.creeCompte(p,n,dt,s,num,dc,c);
}
catch (Exception o) {o.printStackTrace();}
}
else {
double dc = (double)Double.parseDouble(""+txtdecouvert.getValue());
try{
ICompte objet = (ICompte)Naming.lookup("rmi://192.168.1.108/obj");
b = objet.creeCompte(p,n,dt,s,num,dc,c);
}
catch (Exception o) {o.printStackTrace();}
}
if(b==true)
JOptionPane.showMessageDialog (this,"Le compte "+num+" a été créé avec succès!","Creation Compte",JOptionPane.INFORMATION_MESSAGE, null);
else
JOptionPane.showMessageDialog (this,"Impossible de créer le compte. Contacter votre administrateur Système","Erreur Creation Compte",JOptionPane.INFORMATION_MESSAGE, null);
}
}
}
}
}
/* public static void main(String[] args) {
new InterfaceCompte().setVisible(true);
} */
} |
Partager