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
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class Prog1 extends JFrame{
JPanel Panneau;
JLabel Eti1;
JComboBox Combo;
JLabel Eti2;
JTextField Text1;
JButton Bouton;
JLabel Eti3;
public Prog1() {
JPanel Panneau = new JPanel();
FlowLayout Disposition = new FlowLayout();
Panneau.setLayout(Disposition);
JLabel Eti1 =new JLabel("Résidence");
Panneau.add(Eti1);
String[] batiment = new String[]{"A","B"} ;
JComboBox Combo = new JComboBox(batiment);
Panneau.add(Combo);
JLabel Eti2 =new JLabel("Chambre");
Panneau.add(Eti2);
JTextField Text1 = new JTextField(3);
Panneau.add(Text1);
JButton Bouton =new JButton("Associer");
Bouton.addActionListener(new Traitement());
Panneau.add(Bouton);
JLabel Eti3 =new JLabel("0* ** **");
Panneau.add(Eti3);
JFrame f = new JFrame("Prog1");
f.setSize(250,110);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
f.setLocation(dim.width/2 - f.getWidth()/2, dim.height/2 - f.getHeight()/2);
f.setVisible(true);
f.setResizable(false);
f.setContentPane(Panneau);
}
public static void main(String[] args) {
Prog1 Annuaire = new Prog1();
}
public class Traitement implements ActionListener {
public void actionPerformed(ActionEvent e) {
String num="";
String numb="";
num = Text1.getText();
Object bat = Combo.getSelectedItem();
int i = Integer.parseInt(num);
int su=0;
if (bat.equals("A")) {
su = 999+43*((i/100)-1)+(i-100*(i/100));
}
else if (bat.equals("B")) {
su = 999+43*((i/100)+4)+(i-100*(i/100)); }
int ind = *****0000;
int tel = su + ind;
String tel2 = String.valueOf(tel);
tel2 = "0"+tel2;
int compte;
for (compte=0 ; compte <10; compte++ ) {
numb=numb+tel2.charAt(compte);
if (compte%2==1) {numb=numb+" ";
Eti3.setText(numb);
}
}
}
}
} |
Partager