salut tout le monde

j'ai problème avec la couleur rouge de bouton qui montre que nous somes le jour X mais si je change le mois la couleur rouge reste toujours sur le bouton si vendredi reste



pour mieux me comprendre voila le code à executer



Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package mu;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.util.Iterator;
 import java.util.ArrayList;
import java.awt.*;
import java.io.*;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
 
 
 public class ra extends JFrame {
 
            private GregorianCalendar _calendar = new GregorianCalendar();
 
            private DateFormatSymbols _dateSymbols = new DateFormatSymbols();
 
            private SimpleDateFormat _formatMY = new SimpleDateFormat("MMMM yyyy");
 
            private int _firstDayOfWeek = _calendar.getFirstDayOfWeek()+5;
 
            private final JLabel _monthYear = new JLabel("", SwingUtilities.CENTER);
 
            private final JLabel[] _daysOfWeek = new JLabel[7];
 
            private final JButton[] _daysNumber = new JButton[42];
 
 
 
            private final ActionListener _changeMonth = new ActionListener() {
                public void actionPerformed(final ActionEvent ae) {
                    final int nb = "next".equals(ae.getActionCommand()) ? 1: -1;
                    _calendar.add(Calendar.MONTH, nb);
                updateMonthYear();
                updateDaysNumber();
                }
            };
 
 
  private final ActionListener oui = new ActionListener() {
  public void actionPerformed(final ActionEvent e) {
  JButton buttton = (JButton)e.getSource();
  String a=buttton.getText();
  String  s = _calendar.get(Calendar.YEAR)+"/"+a+"/"+_calendar.get(Calendar.MONTH);
 
   setVisible(false);
   chercher A = new chercher();
   A.dd(s);
   A.setVisible(true);
 
   }
  };
 
public ra() {
 
      setTitle(" itemsets frequents  ");
      this.setResizable(false);
      this.setSize(350,350);
      this.setLocationRelativeTo(null);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel panel = new JPanel();
      panel.setLayout(new BorderLayout());
 
 
 
                // Month Panel
                final JPanel monthPanel = new JPanel();
                final JButton previous = new JButton("<<");
                previous.addActionListener(_changeMonth);
                final JButton next = new JButton(">>");
                next.addActionListener(_changeMonth);
 
                _monthYear.setPreferredSize(new Dimension(120, 20));
                monthPanel.add(previous);
                monthPanel.add(_monthYear);
                monthPanel.add(next);
                panel.add(monthPanel, BorderLayout.NORTH);
 
                // Day Panel
                final JPanel dayPanel = new JPanel();
                dayPanel.setLayout(new GridLayout(7, 7));
                for (int i = 0; i < 7; ++i)
                dayPanel.add(_daysOfWeek[i] = new JLabel("",SwingUtilities.CENTER));
                for (int i = 0; i < _daysNumber.length; ++i)
                dayPanel.add(_daysNumber[i] = new JButton());
                panel.add(dayPanel, BorderLayout.CENTER);
                // Remplissage des composants
                updateMonthYear();
                updateDaysOfWeek();
                updateDaysNumber();
 
                setContentPane(panel);
 
            }
 
            private void updateMonthYear() {
                _monthYear.setText(_formatMY.format(_calendar.getTime()));
            }
 
            // Affiche les jours de la semaine
            private void updateDaysOfWeek() {
                final String[] weekDays = _dateSymbols.getShortWeekdays();
                for (int i = 1; i < weekDays.length; ++i) {
 
                    final int index = (i - 2 + _firstDayOfWeek) % 7 + 1;
 
                    _daysOfWeek[i - 1].setText(weekDays[index]);
                }
            }
 
            // Affiche le numéro des jours
            private void updateDaysNumber() {
               int A;
                final Date tmp = _calendar.getTime();
                Calendar now = Calendar.getInstance();
                _calendar.set(Calendar.DAY_OF_MONTH, 1);
                final int firstDay = _calendar.get(Calendar.DAY_OF_WEEK);
                final int LocalFirstDay = (firstDay - _firstDayOfWeek + 7) % 7 + 1;
                boolean full = false;
              int v;
                for (int i = 0; i < _daysNumber.length; ++i) {
 
                    final boolean isNotEmpty = i < LocalFirstDay - 1 || full;
                    _daysNumber[i].setVisible(!isNotEmpty);
 
                    if (!isNotEmpty) {
                        final int dayOfMonth = _calendar.get(Calendar.DAY_OF_MONTH);
                        _daysNumber[i].setText(String.valueOf(dayOfMonth));
                       A =dayOfMonth;
 
                        _calendar.add(Calendar.DAY_OF_MONTH, 1);
                        full = 1 == _calendar.get(Calendar.DAY_OF_MONTH);
                    }
                    if (_calendar.get(Calendar.DAY_OF_WEEK) == 7) {
                _daysNumber[i].setBackground(Color.BLUE);
               }
 
    if(_calendar.get(Calendar.DAY_OF_YEAR)==now.get(Calendar.DAY_OF_YEAR)){
 
 
      if (_calendar.get(Calendar.YEAR) == now.get(Calendar.YEAR)) {
 
          _daysNumber[i + 1].setBackground(Color.red);
 
    }
    }
   _daysNumber[i].addActionListener(oui);
                }
 
                _calendar.setTime(tmp);
            }
 
 
 
            public static void main(final String[] args)
                    {
                  ra gui = new  ra();
                        gui.setVisible(true);
                    }
 
}