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
|
public class New_Rec extends JDialog implements ActionListener {
JLabel date,num,nom,tel,mont,FVer,tel_fix,reste;
JTextField tfnom=creertextField(20);
JFormattedTextField tfmont=creerformtextField();
JFormattedTextField tfFVer=creerformtextField();
JFormattedTextField tftel,tftel_fix;
JTextField tfnum=creertextField(20);
JTextField tfdate=creertextField(20);
JFormattedTextField tfreste=creerformtextField();
JButton bok=new JButton("OK");
JButton ban;
JPanel pan;
New_Rec(){
setTitle("Nouvelle Recette");
pan=new JPanel();
num=creerLabel("Numéro de Bon:");
nom=creerLabel("Nom Client:");
mont=creerLabel("Montant Global:");
FVer=creerLabel("1er Versement:");
date=creerLabel("Date:");
tel=creerLabel("Tel Portable:");
tel_fix=creerLabel("Tel Fix(Domicile):");
reste=creerLabel("Reste:");
MaskFormatter mf = null;
try {
mf = new MaskFormatter("(####) ##-##-##");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
tftel= new JFormattedTextField(mf);
tftel.setBorder(BorderFactory.createLoweredBevelBorder());
tftel.setFont(new Font("verdana.ttf", Font.PLAIN, 15));
MaskFormatter mf2 = null;
try {
mf2 = new MaskFormatter("(###) ##-##-##");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
tftel_fix= new JFormattedTextField(mf2);
tftel_fix.setBorder(BorderFactory.createLoweredBevelBorder());
tftel_fix.setFont(new Font("verdana.ttf", Font.PLAIN, 15));
date.setBounds(90, 100, 50, 25);
tfdate.setBounds(150, 100, 130, 25);
num.setBounds(330, 100, 120, 25);
tfnum.setBounds(450, 100, 180, 25);
nom.setBounds(45, 130, 100, 25);
tfnom.setBounds(150, 130, 480, 25);
FVer.setBounds(20, 160, 120, 25);
tfFVer.setBounds(150, 160, 140, 25);
mont.setBounds(330, 160, 120, 25);
tfmont.setBounds(450, 160, 180, 25);
tel.setBounds(40, 190, 120, 25);
tftel.setBounds(150, 190, 140, 25);
tel_fix.setBounds(320, 190, 140, 25);
tftel_fix.setBounds(450, 190, 180, 25);
reste.setBounds(85, 220, 80, 25);
tfreste.setBounds(150, 220, 140, 25);
ban=new JButton("Annuler");
bok.setBounds(320, 285, 120, 25);
ban.setBounds(450, 285, 120, 25);
pan.setLayout(null);
pan.add(date);
pan.add(num);
pan.add(nom);
pan.add(mont);
pan.add(FVer);
pan.add(tel);
pan.add(tfdate);
pan.add(tfnum);
pan.add(tfnom);
pan.add(tfmont);
pan.add(tfFVer);
pan.add(tftel);
pan.add(tel_fix);
pan.add(tftel_fix);
pan.add(reste);
pan.add(tfreste);
tfreste.setEditable(false);
pan.add(bok);
pan.add(ban);
bok.addActionListener(this);
ban.addActionListener(this);
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
try {
String dateString = formatter.format(today);
tfdate.setText(dateString);
} catch (IllegalArgumentException iae) {}
setContentPane(pan);
setSize(660,400);
setLocationRelativeTo(null);
clear();
tfmont.getDocument().addDocumentListener(new MyDocumentListener());
tfFVer.getDocument().addDocumentListener(new MyDocumentListener());
setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
}});
}
public void clear(){
tfmont.setValue(new Double("0.00"));
tfFVer.setValue(new Double("0.00"));
tfreste.setValue(new Double("0.00"));
}
public static void main(String[] args) {
new New_Rec();
}
public JLabel creerLabel(String titre){
JLabel l=new JLabel(titre);
l.setFont(new Font("verdana.ttf", Font.BOLD, 15));
return l;
}
public static JTextField creertextField(int longueur){
JTextField tf=new JTextField(longueur);
tf.setBorder(BorderFactory.createLoweredBevelBorder());
tf.setFont(new Font("verdana.ttf", Font.PLAIN, 15));
return tf;
}
public static JFormattedTextField creerformtextField(){
NumberFormat format;
format = NumberFormat.getInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
JFormattedTextField tf=new JFormattedTextField(format);
tf.setBorder(BorderFactory.createLoweredBevelBorder());
tf.setFont(new Font("verdana.ttf", Font.PLAIN, 15));
return tf;
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Object obj=arg0.getSource();
if(obj==ban){
try{
dispose();
}catch(Exception e){
e.printStackTrace();
}
}
if(obj==bok){
if("".equals(tfnom.getText()) || "".equals(tfmont.getText())||"".equals(tfFVer.getText())){
JOptionPane.showMessageDialog(null, "Il faut remplir tous les champs ");
}else{
dispose();
}
}
}
class MyDocumentListener implements DocumentListener {
public void changedUpdate(DocumentEvent arg0) {
}
public void insertUpdate(DocumentEvent arg0) {
Update_Reste();
}
public void removeUpdate(DocumentEvent arg0) {
Update_Reste();
}
public void Update_Reste(){
double montgl_value=((Number)tfmont.getValue()).doubleValue();
double montver_value=((Number)tfFVer.getValue()).doubleValue();
tfreste.setValue(montgl_value-montver_value);
}
}
} |
Partager