質問編集履歴
2
///
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,257 +1,29 @@
|
|
1
|
-
|
1
|
+
/**
|
2
2
|
|
3
|
-
|
3
|
+
* カレンダーの表示月を調整する
|
4
4
|
|
5
|
-
pr
|
5
|
+
* @param month 表示する月−1
|
6
6
|
|
7
|
+
*/
|
7
8
|
|
9
|
+
private void changeMonth(int month) {
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
b1.addActionListener(new ActionListener() {
|
12
|
-
|
13
|
-
public void actionPerformed(ActionEvent ae) {
|
14
|
-
|
15
|
-
cal.add(Calendar.MONTH, -1);
|
16
|
-
|
17
|
-
//b.1のmonthLabelの減少処理
|
18
|
-
|
19
|
-
int targetMonth = 999;
|
20
|
-
|
21
|
-
int year = cal.get(Calendar.YEAR);
|
22
|
-
|
23
|
-
String month = monthLabel.getText();
|
24
|
-
|
25
|
-
for(int i = 0; i < MONTH_NAMES.length; i++) {
|
26
|
-
|
27
|
-
|
11
|
+
monthLabel.setText(MONTH_NAMES[month]);
|
28
|
-
|
29
|
-
targetMonth = i - 1;
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
//b1のyearLabelの減少処理
|
38
|
-
|
39
|
-
if(targetMonth == -1) {
|
40
|
-
|
41
|
-
targetMonth = 11;
|
42
|
-
|
43
|
-
year = cal.get(Calendar.YEAR);
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
changeMonth(targetMonth);
|
48
|
-
|
49
|
-
changeYear(year);
|
50
|
-
|
51
|
-
updateMonth(cal, true);
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
});
|
56
|
-
|
57
|
-
/*b2Button*/
|
58
|
-
|
59
|
-
b2.addActionListener(new ActionListener() {
|
60
|
-
|
61
|
-
public void actionPerformed(ActionEvent ae) {
|
62
|
-
|
63
|
-
cal.add(Calendar.MONTH, +1);
|
64
|
-
|
65
|
-
//b2のmonthLabelの増やす処理
|
66
|
-
|
67
|
-
int targetMonth = 999;
|
68
|
-
|
69
|
-
int year = cal.get(Calendar.YEAR);
|
70
|
-
|
71
|
-
String month = monthLabel.getText();
|
72
|
-
|
73
|
-
for (int i = 0; i < MONTH_NAMES.length; i++) {
|
74
|
-
|
75
|
-
if(month.equals(MONTH_NAMES[i])) {
|
76
|
-
|
77
|
-
targetMonth = i +1;
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
//b2のyearLabelの増やす処理
|
84
|
-
|
85
|
-
if(targetMonth == 12) {
|
86
|
-
|
87
|
-
targetMonth = 0;
|
88
|
-
|
89
|
-
year = cal.get(Calendar.YEAR);
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
changeMonth(targetMonth);
|
96
|
-
|
97
|
-
changeYear(year);
|
98
|
-
|
99
|
-
updateMonth(cal, true);
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
});
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
private void updateMonth(Calendar cal, boolean currentMonth) {
|
108
|
-
|
109
|
-
int maxDate = cal.getActualMaximum(Calendar.DATE);
|
110
|
-
|
111
|
-
int today = cal.get(Calendar.DATE);
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
cal.set(Calendar.DATE, 1);
|
118
|
-
|
119
|
-
int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
for( JLabel[] ll : dayLabels) {
|
124
|
-
|
125
|
-
for( JLabel l : ll ) {
|
126
|
-
|
127
|
-
l.setText("");
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
for( int day=1; day<=maxDate; day++ ) {
|
136
|
-
|
137
|
-
getDayLabel( day, firstDayOfWeek ).setText(Integer.toString(day));
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
for( int i=0; i<dayLabels.length; i++) {
|
144
|
-
|
145
|
-
for( int j=0; j<dayLabels[i].length; j++) {
|
146
|
-
|
147
|
-
JLabel l = dayLabels[i][j];
|
148
|
-
|
149
|
-
l.setBackground(DAY_BG);
|
150
|
-
|
151
|
-
l.setForeground(DAY_FG);
|
152
|
-
|
153
|
-
l.setBorder(DAY_BORDER);
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if( l.getText().length() != 0 ) {
|
158
|
-
|
159
|
-
l.setVisible(true);
|
160
|
-
|
161
|
-
} else {
|
162
|
-
|
163
|
-
l.setVisible(false);
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
if( currentMonth) {
|
178
|
-
|
179
|
-
JLabel l = getDayLabel( today, firstDayOfWeek );
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
l.setBackground(TODAY_BG);
|
184
|
-
|
185
|
-
l.setForeground(TODAY_FG);
|
186
|
-
|
187
|
-
l.setBorder(TODAY_BORDER);
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
12
|
|
193
13
|
}
|
194
14
|
|
15
|
+
/**
|
195
16
|
|
17
|
+
* カレンダーの表示年を調節する
|
196
18
|
|
197
|
-
pr
|
19
|
+
* @param year 表示する年
|
198
20
|
|
199
|
-
|
21
|
+
*/
|
200
22
|
|
201
|
-
|
23
|
+
private void changeYear(int year) {
|
202
24
|
|
203
|
-
|
25
|
+
String s = Integer.toString(year);
|
204
26
|
|
205
|
-
|
27
|
+
yearLabel.setText(s);
|
206
28
|
|
207
|
-
|
208
|
-
|
209
|
-
現在カレンダーアプリの作成をしています。
|
210
|
-
|
211
|
-
< > ボタンで月を変えられるようにしています。
|
212
|
-
|
213
|
-
月の取得まではできています。
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
### 発生している問題・エラーメッセージ
|
220
|
-
|
221
|
-
<>ボタンを押す⇒月が変わる⇒<>で再び当月へ戻る
|
222
|
-
|
223
|
-
とすると、当日の取得ができなくなってしまいます。
|
224
|
-
|
225
|
-
|
29
|
+
}
|
226
|
-
|
227
|
-
エラーメッセージ
|
228
|
-
|
229
|
-
```
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
### 該当のソースコード
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
```ここに言語名を入力
|
238
|
-
|
239
|
-
ソースコード
|
240
|
-
|
241
|
-
```
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
ここに問題に対して試したことを記載してください。
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
### 補足情報(FW/ツールのバージョンなど)
|
1
初めてで質問内容に不備があり申し訳ありません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,208 @@
|
|
1
|
+
```"Java"
|
2
|
+
|
3
|
+
private JButton b1 = new JButton("<");
|
4
|
+
|
5
|
+
private JButton b2 = new JButton(">");
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
b1.addActionListener(new ActionListener() {
|
12
|
+
|
13
|
+
public void actionPerformed(ActionEvent ae) {
|
14
|
+
|
15
|
+
cal.add(Calendar.MONTH, -1);
|
16
|
+
|
17
|
+
//b.1のmonthLabelの減少処理
|
18
|
+
|
19
|
+
int targetMonth = 999;
|
20
|
+
|
21
|
+
int year = cal.get(Calendar.YEAR);
|
22
|
+
|
23
|
+
String month = monthLabel.getText();
|
24
|
+
|
25
|
+
for(int i = 0; i < MONTH_NAMES.length; i++) {
|
26
|
+
|
27
|
+
if(month.equals(MONTH_NAMES[i])) {
|
28
|
+
|
29
|
+
targetMonth = i - 1;
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
//b1のyearLabelの減少処理
|
38
|
+
|
39
|
+
if(targetMonth == -1) {
|
40
|
+
|
41
|
+
targetMonth = 11;
|
42
|
+
|
43
|
+
year = cal.get(Calendar.YEAR);
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
changeMonth(targetMonth);
|
48
|
+
|
49
|
+
changeYear(year);
|
50
|
+
|
51
|
+
updateMonth(cal, true);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
});
|
56
|
+
|
57
|
+
/*b2Button*/
|
58
|
+
|
59
|
+
b2.addActionListener(new ActionListener() {
|
60
|
+
|
61
|
+
public void actionPerformed(ActionEvent ae) {
|
62
|
+
|
63
|
+
cal.add(Calendar.MONTH, +1);
|
64
|
+
|
65
|
+
//b2のmonthLabelの増やす処理
|
66
|
+
|
67
|
+
int targetMonth = 999;
|
68
|
+
|
69
|
+
int year = cal.get(Calendar.YEAR);
|
70
|
+
|
71
|
+
String month = monthLabel.getText();
|
72
|
+
|
73
|
+
for (int i = 0; i < MONTH_NAMES.length; i++) {
|
74
|
+
|
75
|
+
if(month.equals(MONTH_NAMES[i])) {
|
76
|
+
|
77
|
+
targetMonth = i +1;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
//b2のyearLabelの増やす処理
|
84
|
+
|
85
|
+
if(targetMonth == 12) {
|
86
|
+
|
87
|
+
targetMonth = 0;
|
88
|
+
|
89
|
+
year = cal.get(Calendar.YEAR);
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
changeMonth(targetMonth);
|
96
|
+
|
97
|
+
changeYear(year);
|
98
|
+
|
99
|
+
updateMonth(cal, true);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
private void updateMonth(Calendar cal, boolean currentMonth) {
|
108
|
+
|
109
|
+
int maxDate = cal.getActualMaximum(Calendar.DATE);
|
110
|
+
|
111
|
+
int today = cal.get(Calendar.DATE);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
cal.set(Calendar.DATE, 1);
|
118
|
+
|
119
|
+
int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
for( JLabel[] ll : dayLabels) {
|
124
|
+
|
125
|
+
for( JLabel l : ll ) {
|
126
|
+
|
127
|
+
l.setText("");
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
for( int day=1; day<=maxDate; day++ ) {
|
136
|
+
|
137
|
+
getDayLabel( day, firstDayOfWeek ).setText(Integer.toString(day));
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
for( int i=0; i<dayLabels.length; i++) {
|
144
|
+
|
145
|
+
for( int j=0; j<dayLabels[i].length; j++) {
|
146
|
+
|
147
|
+
JLabel l = dayLabels[i][j];
|
148
|
+
|
149
|
+
l.setBackground(DAY_BG);
|
150
|
+
|
151
|
+
l.setForeground(DAY_FG);
|
152
|
+
|
153
|
+
l.setBorder(DAY_BORDER);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
if( l.getText().length() != 0 ) {
|
158
|
+
|
159
|
+
l.setVisible(true);
|
160
|
+
|
161
|
+
} else {
|
162
|
+
|
163
|
+
l.setVisible(false);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
if( currentMonth) {
|
178
|
+
|
179
|
+
JLabel l = getDayLabel( today, firstDayOfWeek );
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
l.setBackground(TODAY_BG);
|
184
|
+
|
185
|
+
l.setForeground(TODAY_FG);
|
186
|
+
|
187
|
+
l.setBorder(TODAY_BORDER);
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
private JLabel getDayLabel( int day , int firstDayOfWeek ) {
|
198
|
+
|
199
|
+
return dayLabels[(day + firstDayOfWeek - 2)/7][(day + firstDayOfWeek - 2)%7];
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
1
|
-
### 前提・実現したいこと
|
205
|
+
```### 前提・実現したいこと
|
2
206
|
|
3
207
|
|
4
208
|
|
@@ -8,7 +212,7 @@
|
|
8
212
|
|
9
213
|
月の取得まではできています。
|
10
214
|
|
11
|
-
|
215
|
+
|
12
216
|
|
13
217
|
|
14
218
|
|
@@ -38,211 +242,11 @@
|
|
38
242
|
|
39
243
|
|
40
244
|
|
41
|
-
|
245
|
+
|
42
|
-
|
43
|
-
|
246
|
+
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
247
|
+
|
50
|
-
|
51
|
-
|
248
|
+
|
52
|
-
|
53
|
-
|
249
|
+
|
54
|
-
|
55
|
-
//b.1のmonthLabelの減少処理
|
56
|
-
|
57
|
-
int targetMonth = 999;
|
58
|
-
|
59
|
-
int year = cal.get(Calendar.YEAR);
|
60
|
-
|
61
|
-
String month = monthLabel.getText();
|
62
|
-
|
63
|
-
for(int i = 0; i < MONTH_NAMES.length; i++) {
|
64
|
-
|
65
|
-
if(month.equals(MONTH_NAMES[i])) {
|
66
|
-
|
67
|
-
targetMonth = i - 1;
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
//b1のyearLabelの減少処理
|
76
|
-
|
77
|
-
if(targetMonth == -1) {
|
78
|
-
|
79
|
-
targetMonth = 11;
|
80
|
-
|
81
|
-
year = cal.get(Calendar.YEAR);
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
changeMonth(targetMonth);
|
86
|
-
|
87
|
-
changeYear(year);
|
88
|
-
|
89
|
-
updateMonth(cal, true);
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
});
|
94
|
-
|
95
|
-
/*b2Button*/
|
96
|
-
|
97
|
-
b2.addActionListener(new ActionListener() {
|
98
|
-
|
99
|
-
public void actionPerformed(ActionEvent ae) {
|
100
|
-
|
101
|
-
cal.add(Calendar.MONTH, +1);
|
102
|
-
|
103
|
-
//b2のmonthLabelの増やす処理
|
104
|
-
|
105
|
-
int targetMonth = 999;
|
106
|
-
|
107
|
-
int year = cal.get(Calendar.YEAR);
|
108
|
-
|
109
|
-
String month = monthLabel.getText();
|
110
|
-
|
111
|
-
for (int i = 0; i < MONTH_NAMES.length; i++) {
|
112
|
-
|
113
|
-
if(month.equals(MONTH_NAMES[i])) {
|
114
|
-
|
115
|
-
targetMonth = i +1;
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
//b2のyearLabelの増やす処理
|
122
|
-
|
123
|
-
if(targetMonth == 12) {
|
124
|
-
|
125
|
-
targetMonth = 0;
|
126
|
-
|
127
|
-
year = cal.get(Calendar.YEAR);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
changeMonth(targetMonth);
|
134
|
-
|
135
|
-
changeYear(year);
|
136
|
-
|
137
|
-
updateMonth(cal, true);
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
});
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
private void updateMonth(Calendar cal, boolean currentMonth) {
|
146
|
-
|
147
|
-
int maxDate = cal.getActualMaximum(Calendar.DATE);
|
148
|
-
|
149
|
-
int today = cal.get(Calendar.DATE);
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
cal.set(Calendar.DATE, 1);
|
156
|
-
|
157
|
-
int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
for( JLabel[] ll : dayLabels) {
|
162
|
-
|
163
|
-
for( JLabel l : ll ) {
|
164
|
-
|
165
|
-
l.setText("");
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
for( int day=1; day<=maxDate; day++ ) {
|
174
|
-
|
175
|
-
getDayLabel( day, firstDayOfWeek ).setText(Integer.toString(day));
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
for( int i=0; i<dayLabels.length; i++) {
|
182
|
-
|
183
|
-
for( int j=0; j<dayLabels[i].length; j++) {
|
184
|
-
|
185
|
-
JLabel l = dayLabels[i][j];
|
186
|
-
|
187
|
-
l.setBackground(DAY_BG);
|
188
|
-
|
189
|
-
l.setForeground(DAY_FG);
|
190
|
-
|
191
|
-
l.setBorder(DAY_BORDER);
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
if( l.getText().length() != 0 ) {
|
196
|
-
|
197
|
-
l.setVisible(true);
|
198
|
-
|
199
|
-
} else {
|
200
|
-
|
201
|
-
l.setVisible(false);
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
if( currentMonth) {
|
216
|
-
|
217
|
-
JLabel l = getDayLabel( today, firstDayOfWeek );
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
l.setBackground(TODAY_BG);
|
222
|
-
|
223
|
-
l.setForeground(TODAY_FG);
|
224
|
-
|
225
|
-
l.setBorder(TODAY_BORDER);
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
private JLabel getDayLabel( int day , int firstDayOfWeek ) {
|
236
|
-
|
237
|
-
return dayLabels[(day + firstDayOfWeek - 2)/7][(day + firstDayOfWeek - 2)%7];
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
### 試したこと
|
246
250
|
|
247
251
|
|
248
252
|
|
@@ -251,7 +255,3 @@
|
|
251
255
|
|
252
256
|
|
253
257
|
### 補足情報(FW/ツールのバージョンなど)
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
ここにより詳細な情報を記載してください。
|