| 12
 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
 
 | public class Calendar {
    ...
    static JComboBox monthsCombo;
    static String[] months;
    static Month[] onlyMonths;
    ...
 
    public Calendar(JPanel westMainWindowPanel, Locale locale){ 
 	...
	monthsCombo = new JComboBox();
        updateMonth();
  	...	
	monthsCombo.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
		System.out.println(monthsCombo.getSelectedItem()); // Affichage de null			
                System.out.println(((Month)monthsCombo.getSelectedItem()).getMonthIndex()); // J'ai l'exception qui se fini ici
	            ...
	     }
            }); 
    }
 
    // MAJ du calendrier
    protected static void updateCalendarLocale(Locale locale){ 
            ...	
            updateMonth();
	    // Les autres MAJ
            ...
    }
 
    // MAJ du combo box des mois
    private static void updateMonth(){ 
        // Je récupère les mois en fonction de la locale
    	months = dateSymbols.getMonths();
    	onlyMonths = new Month[Calendar.UNDECIMBER];
    	String month = "";
 
        // Ce for permet d'enlever le 13ième mois vide retourné par la méthode getMonths() et d'avoir des couples (numéro du mois, nom du mois)
 	for (int i = Calendar.JANUARY; i < Calendar.UNDECIMBER; i++){
 	         month = months[i].substring(0,1).toUpperCase()+months[i].substring(1);
 	         onlyMonths[i] = new Month(i, month);
 	}
 
        // Je test si le combo a déjà été affiché
        // Si c'est le cas je le met à jour, du moins j'essaye parce que c'est ici que ça bloque
	if (monthsCombo.getItemCount() == 12) {
                 // J'ai l'exception qui commence ici
 	         monthsCombo.removeAllItems();			
 
                 // Je rempli le JcomboBox avec les nouvelles valeurs
 	         for (int i = Calendar.JANUARY; i < Calendar.UNDECIMBER; i++){
                          monthsCombo.addItem(onlyMonths[i]);
                          System.out.println(monthsCombo.getItemAt(i));
 	         }
	}
        // Sinon je le crée
	else {
		monthsCombo = new JComboBox(onlyMonths);
	}
 
	monthsCombo.setSelectedIndex(selectedMonth);
    }
} | 
Partager