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
|
public class SousFenetre extends JPanel {
int Demandei[] = {0, 0, 0, 0, 0};
int p = 0;
int CoutTotaleDePeriode[][] = new int[p][p+1];
int L, M, QuantitéàProduite;
int CoutFabrication;
int CoutStock;
int A[] = {0, 0, 0, 0, 0, 0};
int f[] = {0, 0, 0, 0, 0, 0};
private static final int MARGIN = 10;
private static final long serialVersionUID = 1L;
private Map<String, JTextField> fieldMap = new HashMap<String, JTextField>();
List<Integer> listInt = new ArrayList<Integer>();
public final static String FIELD_INITVAR_PERIODE = "Periode";
public final static String FIELD_INITVAR_DEMANDEP = "demandeP";
JTextField DemandeP,Periode;
JButton btnCalculer,btnAfficher,demandePValide,periodeValide;
JLabel resultatGauche;
JPanel p1,p2;
public SousFenetre() {
setBorder(BorderFactory.createEmptyBorder(MARGIN,MARGIN,MARGIN,MARGIN)); // une petite bordure pour ne pas être collé au bord de la fenêtre
setLayout(new GridLayout(2,1,MARGIN,MARGIN)); // grille 2 x 2
this.setBackground(Color.LIGHT_GRAY); // Couleur de Fenetre
// ajoute des 4 panels
add(creerPanelHaut());
add(creerPanelBas());
}
public JPanel creerPanelHaut() {
p2 = creerPanelAvecTitre("Initialisation les variables :");
p2.setBackground(Color.LIGHT_GRAY);
btnCalculer = new JButton("Calculer");
btnCalculer.addActionListener(new BtnCalculerListener());
p2.add(btnCalculer,BorderLayout.SOUTH);
Box hBox1 = Box.createHorizontalBox();
hBox1.add(btnCalculer);
btnAfficher = new JButton("Afficher la résultat : ");
btnAfficher.addActionListener(new BtnCalculerListener());
Box hBox2 = Box.createHorizontalBox();
hBox2.add(btnAfficher);
Box vBox = Box.createHorizontalBox();
vBox.add(hBox1);
vBox.add(hBox2);
p2.add(vBox,BorderLayout.SOUTH);
p2.add(SaisieHPanel(), BorderLayout.CENTER);
return p2;
}
public JPanel creerPanelBas() {
p1 = creerPanelAvecTitre("Résultat :");
p1.setBackground(Color.white); // ça tu l'ajoutes (je l'avais pas mis, je ne pouvais pas savoir au moment ou j'ai posté le code que tu le voulais en blanc)
p1.add(SaisieBPanel(), BorderLayout.CENTER);
return p1;
}
public JPanel SaisieHPanel() {
JPanel panel = new JPanel();
panel.setBackground(Color.LIGHT_GRAY);
SpringLayout layout = new SpringLayout();
panel.setLayout(layout); // panel.setLayout(new GridLayout(2,1));
JLabel PeriodeLabel = new JLabel("Le Periode : ");
panel.add( PeriodeLabel );
Periode = new JTextField();
Periode.setColumns(3);
fieldMap.put( FIELD_INITVAR_PERIODE, Periode );
panel.add(Periode);
periodeValide = new JButton("Validée");
periodeValide.addActionListener(new periodeValideListener());
panel.add(periodeValide);
JLabel DemandePLabel = new JLabel("Demande de Période : ");
panel.add(DemandePLabel );
DemandeP = new JTextField();
DemandeP.setColumns(3);
fieldMap.put( FIELD_INITVAR_DEMANDEP, DemandeP );
panel.add(DemandeP);
demandePValide = new JButton("Validée");
demandePValide.addActionListener(new DemandePValideListener());
panel.add(demandePValide);
SpringUtilities.makeCompactGrid(panel, 2, 3, 20, 0, 20, 10);
return panel;
}
public JPanel SaisieBPanel(){
JPanel panel = new JPanel();
panel.setBackground(Color.white);
SpringLayout layout = new SpringLayout();
panel.setLayout(layout);
return panel;
}
public JPanel creerPanelAvecTitre(String titre) {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); // un cadre autour
panel.setLayout(new BorderLayout(MARGIN, MARGIN));
JLabel titreLabel = new JLabel(titre);// création du titre du panel
titreLabel.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); // appeler à les titres
panel.add(titreLabel, BorderLayout.NORTH); // texte en haut du panel
return panel;
}
public JPanel getP1() {
return p1;
}
public void setP1(JPanel p1) {
this.p1 = p1;
}
public JPanel getP2() {
return p2;
}
public void setP2(JPanel p2) {
this.p2 = p2;
}
class BtnCalculerListener implements ActionListener {
public void actionPerformed(ActionEvent arg0){
float f = Float.valueOf(DemandeP.getText());
resultatGauche.setText(String.valueOf(f));
for(int i=0; i<listInt.size();i++){
Demandei[i]=listInt.get(i);
}
JPanel panel = new JPanel();
panel.add(TraitementPanel(), BorderLayout.CENTER);
}
}
public JPanel TraitementPanel(){
JPanel panel = new JPanel();
panel.setBackground(Color.LIGHT_GRAY);
SpringLayout layout = new SpringLayout();
panel.setLayout(layout);
System.out.println("\n\ti \tk \tXi \tCoutFabrication \tCoutStock \tCT");
for( int periodedeproduction=1;periodedeproduction<=p-1;periodedeproduction++ ){
L=0; M=0;
for( int Productionàfaire=periodedeproduction+1;Productionàfaire<=p;Productionàfaire++ ){
if ( Productionàfaire == periodedeproduction+1 ) {
CoutStock=0;
} else {
CoutStock = M+(Productionàfaire-(periodedeproduction+1))*Demandei[Productionàfaire-1];
}
QuantitéàProduite = Demandei[Productionàfaire-1]+L;
L = QuantitéàProduite;
CoutFabrication = 100 + 2*QuantitéàProduite;
CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1] = CoutFabrication + CoutStock;
System.out.println("\n\t"+periodedeproduction+"\t"+Productionàfaire+"\t"+QuantitéàProduite+"\t"+CoutFabrication+"\t"+CoutStock+"\t"+CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1]);
M = CoutStock;
f[0] =0;
A[periodedeproduction] = CoutTotaleDePeriode[periodedeproduction-1][periodedeproduction]+CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1];
//int l =periodedeproduction-1;
//System.out.println("\t"+"f["+periodedeproduction+"]"+"+"+"CoutTotaleDePeriode["+periodedeproduction+"]["+typeDeProduction+"]"+"="+A[periodedeproduction]);
f[Productionàfaire]= A[periodedeproduction];
//System.out.println("\t"+"f["+typeDeProduction+"]"+"="+f[typeDeProduction]);
}
}
//
return panel;
}
class DemandePValideListener implements ActionListener {
public void actionPerformed(ActionEvent arg0){
listInt.add(Integer.valueOf(DemandeP.getText()));
for(Integer i : listInt){
System.out.println(i);
}
}
}
class periodeValideListener implements ActionListener {
public void actionPerformed(ActionEvent arg0){
Periode.setEditable(false);
}
}
public void setField(String id, String valeur) {
JTextField field = fieldMap.get(id);
if ( field!=null ) field.setText(valeur);
}
public String getField(String id) {
JTextField field = fieldMap.get(id);
if ( field!=null ) {
return field.getText();
} else {
throw new IllegalArgumentException();
}
}
} |
Partager