質問編集履歴

5

日付の配列修正

2018/08/17 09:23

投稿

shuriboo
shuriboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -192,49 +192,37 @@
192
192
 
193
193
 
194
194
 
195
+
196
+
195
197
   //日付の配列
196
198
 
197
-  for( int i=0; i<6; i++) {
199
+ for( int i=0; i<6; i++) {
198
-
200
+
199
-   for( int j=0; j<7; j++) {
201
+    for( int j=0; j<7; j++) {
200
-
202
+
201
-    dayLabels[i][j] = new JLabel(); //String.valueOf(i),(j)
203
+  dayLabels[i][j] = new DayLabel("test");
202
-
203
-    dayLabels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
204
+
204
-
205
-    dayLabels[i][j].setVerticalAlignment(SwingConstants.CENTER);
205
+
206
-
207
-    dayLabels[i][j].setOpaque(true);
206
+
208
-
209
-    dayLabels[i][j].setBackground(DAY_BG);
210
-
211
-    dayLabels[i][j].setPreferredSize(DAY_LABEL_SIZE);
212
-
213
-    System.out.println("i" + i); //確認
214
-
215
-    System.out.println("j" + j); //確認
216
-
217
-
218
-
219
-
220
-
221
-     if( i == 0 && j == 0 ) {
207
+ if(j == 0 ) {
222
-
208
+
223
-       dayLabels[i][j].setForeground(Color.RED);
209
+   dayLabels[i][j].setForeground(Color.RED);
224
-
210
+
225
-     } else if ( i == 6 && j == 0 ) {
211
+ } else if (j == 6 ) {
226
-
212
+
227
-       dayLabels[i][j].setForeground(Color.BLUE);
213
+   dayLabels[i][j].setForeground(Color.BLUE);
228
-
214
+
229
-     }
215
+ }
230
216
 
231
217
 
232
218
 
233
219
        dayPanel.add(dayLabels[i][j]);
234
220
 
235
-    }
221
+      }
222
+
236
-
223
+       System.out.println("i" + i); //確認
224
+
237
-
225
+  System.out.println("j" + j); //確認
238
226
 
239
227
    }
240
228
 

4

code修正

2018/08/17 09:23

投稿

shuriboo
shuriboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1,9 +1,281 @@
1
1
  ```Java
2
2
 
3
+ import java.awt.Color;
4
+
5
+ import java.awt.Dimension;
6
+
7
+ import java.awt.GridLayout;
8
+
9
+ import java.util.Calendar;
10
+
11
+
12
+
13
+ import javax.swing.BoxLayout;
14
+
15
+ import javax.swing.JFrame;
16
+
17
+ import javax.swing.JLabel;
18
+
19
+ import javax.swing.JPanel;
20
+
21
+ import javax.swing.SwingConstants;
22
+
23
+ import javax.swing.UIManager;
24
+
25
+ import javax.swing.UnsupportedLookAndFeelException;
26
+
27
+ import javax.swing.border.LineBorder;
28
+
29
+
30
+
31
+ public class debugTest {
32
+
33
+ public static void main(String[] args) {
34
+
35
+ JFrame frame = new JFrame("Swing Calender");
36
+
37
+ frame.add(new SwingCalendar());
38
+
39
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
40
+
41
+ frame.pack();
42
+
43
+ frame.setVisible(true);
44
+
45
+ }
46
+
47
+ }
48
+
49
+
50
+
51
+ class SwingCalendar extends JPanel {
52
+
53
+ private JLabel monthLabel = new JLabel();
54
+
55
+ private JLabel yearLabel = new JLabel();
56
+
57
+ Calendar cal = Calendar.getInstance();
58
+
59
+
60
+
61
+ //曜日、日付ラベル作成
62
+
63
+ private JLabel[] weekLabels = new JLabel[7];
64
+
65
+ private JLabel[][] dayLabels = new JLabel[6][7];
66
+
67
+
68
+
69
+  //各パーツのColorの作成
70
+
71
+  private static final Color WEEK_BG = new Color(102,102,102);
72
+
73
+  //private static final LineBorder WEEK_BORDER = new LineBorder(new  Color(160,160,230), 2, false);
74
+
75
+
76
+
77
+  //日付パネルの色
78
+
79
+  private static final Color DAY_BG = new Color(102,102,102);
80
+
81
+  private static final Color DAY_FG = Color.BLACK;
82
+
83
+  private static final LineBorder DAY_BORDER = new LineBorder(new Color(102,102,102), 2, false);
84
+
85
+
86
+
87
+  //日付のLabel
88
+
89
+  private static final Dimension DAY_LABEL_SIZE = new Dimension(50,50);
90
+
3
- //////////////////////////////
91
+  private static final String[] WEEK_NAMES = new String[] {"日", "月", "火", "水", "木", "金", "土"};
4
-
5
- 現在コードの修正中です。
92
+
6
-
7
- //////////////////////////////
93
+  private static final String[] MONTH_NAMES = new String[] {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
94
+
95
+
96
+
97
+  public SwingCalendar() {
98
+
99
+  try {
100
+
101
+  UIManager.setLookAndFeel(
102
+
103
+  "javax.swing.plaf.nimbus.NimbusLookAndFeel"
104
+
105
+  );
106
+
107
+  } catch (ClassNotFoundException | InstantiationException
108
+
109
+  | IllegalAccessException | UnsupportedLookAndFeelException e) {
110
+
111
+  e.printStackTrace();
112
+
113
+  }
114
+
115
+
116
+
117
+  /* MONTH Label */
118
+
119
+  Dimension dm = monthLabel.getPreferredSize();
120
+
121
+  dm.width += 10; //dm.height += 1;
122
+
123
+  monthLabel.setPreferredSize(dm);
124
+
125
+  monthLabel.setForeground(DAY_FG);
126
+
127
+
128
+
129
+  /* YEAR Label */
130
+
131
+  Dimension dy = yearLabel.getPreferredSize();
132
+
133
+  dy.width += 10; //dy.height += 1;
134
+
135
+  yearLabel.setPreferredSize(dy);
136
+
137
+  yearLabel.setForeground(DAY_FG);
138
+
139
+
140
+
141
+  /* DAY PANEL */
142
+
143
+  JPanel dayPanel = new JPanel();
144
+
145
+  GridLayout layout = new GridLayout(7, 7);
146
+
147
+  layout.setHgap(0);
148
+
149
+  layout.setVgap(0);
150
+
151
+  dayPanel.setLayout(layout);
152
+
153
+  dayPanel.setBackground(DAY_BG);
154
+
155
+
156
+
157
+  //曜日の配列
158
+
159
+  for( int i=0; i<7; i++) {
160
+
161
+   weekLabels[i] = new JLabel(WEEK_NAMES[i]);
162
+
163
+   weekLabels[i].setHorizontalAlignment(SwingConstants.CENTER);
164
+
165
+   weekLabels[i].setVerticalAlignment(SwingConstants.CENTER);
166
+
167
+   weekLabels[i].setPreferredSize(DAY_LABEL_SIZE);
168
+
169
+   weekLabels[i].setOpaque(true);
170
+
171
+   weekLabels[i].setBackground(WEEK_BG);
172
+
173
+  
174
+
175
+   if( i == 0 ) {
176
+
177
+     weekLabels[i].setForeground(Color.RED);
178
+
179
+   } else if ( i == 6 ) {
180
+
181
+     weekLabels[i].setForeground(Color.BLUE);
182
+
183
+   }
184
+
185
+
186
+
187
+   System.out.println("kakunin" + i);
188
+
189
+   dayPanel.add(weekLabels[i]);
190
+
191
+  }
192
+
193
+
194
+
195
+  //日付の配列
196
+
197
+  for( int i=0; i<6; i++) {
198
+
199
+   for( int j=0; j<7; j++) {
200
+
201
+    dayLabels[i][j] = new JLabel(); //String.valueOf(i),(j)
202
+
203
+    dayLabels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
204
+
205
+    dayLabels[i][j].setVerticalAlignment(SwingConstants.CENTER);
206
+
207
+    dayLabels[i][j].setOpaque(true);
208
+
209
+    dayLabels[i][j].setBackground(DAY_BG);
210
+
211
+    dayLabels[i][j].setPreferredSize(DAY_LABEL_SIZE);
212
+
213
+    System.out.println("i" + i); //確認
214
+
215
+    System.out.println("j" + j); //確認
216
+
217
+
218
+
219
+
220
+
221
+     if( i == 0 && j == 0 ) {
222
+
223
+       dayLabels[i][j].setForeground(Color.RED);
224
+
225
+     } else if ( i == 6 && j == 0 ) {
226
+
227
+       dayLabels[i][j].setForeground(Color.BLUE);
228
+
229
+     }
230
+
231
+
232
+
233
+       dayPanel.add(dayLabels[i][j]);
234
+
235
+    }
236
+
237
+
238
+
239
+   }
240
+
241
+
242
+
243
+   JPanel monthPanel = new JPanel();
244
+
245
+   monthPanel.setLayout(new GridLayout());
246
+
247
+   monthPanel.add(yearLabel);
248
+
249
+   monthPanel.add(monthLabel);
250
+
251
+   monthPanel.setBackground(DAY_BG);
252
+
253
+
254
+
255
+   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
256
+
257
+   GridLayout gl = new GridLayout(1,2);
258
+
259
+   gl.setHgap(10); gl.setVgap(10);
260
+
261
+
262
+
263
+   //年月ボタン表示パネル、日にちパネルの追加
264
+
265
+   add(monthPanel);
266
+
267
+   add(dayPanel);
268
+
269
+
270
+
271
+  }
272
+
273
+
274
+
275
+ }
276
+
277
+
278
+
279
+
8
280
 
9
281
  ```

3

///

2018/08/17 06:23

投稿

shuriboo
shuriboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1,299 +1,9 @@
1
1
  ```Java
2
2
 
3
- import java.awt.Color;
3
+ //////////////////////////////
4
4
 
5
- import java.awt.Dimension;
5
+ 現在コードの修正中です。
6
6
 
7
- import java.awt.GridLayout;
8
-
9
- import java.util.Calendar;
10
-
11
-
12
-
13
- import javax.swing.BoxLayout;
14
-
15
- import javax.swing.JFrame;
16
-
17
- import javax.swing.JLabel;
18
-
19
- import javax.swing.JPanel;
20
-
21
- import javax.swing.SwingConstants;
22
-
23
- import javax.swing.UIManager;
24
-
25
- import javax.swing.UnsupportedLookAndFeelException;
26
-
27
- import javax.swing.border.LineBorder;
28
-
29
-
30
-
31
- public class debugTest {
32
-
33
- public static void main(String[] args) {
34
-
35
- JFrame frame = new JFrame("Swing Calender");
36
-
37
- // frame.setSize(400,600);
38
-
39
- frame.add(new SwingCalendar());
40
-
41
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42
-
43
- frame.pack();
44
-
45
- frame.setVisible(true);
46
-
47
- }
48
-
49
- }
50
-
51
-
52
-
53
- class SwingCalendar extends JPanel {
54
-
55
- //月のLabelの宣言
56
-
57
- private JLabel monthLabel = new JLabel();
58
-
59
- //年のLabelの宣言
60
-
61
- private JLabel yearLabel = new JLabel();
62
-
63
- //Calendarクラスのインスタンス化取得
64
-
65
- Calendar cal = Calendar.getInstance();
66
-
67
-
68
-
69
- //曜日のLabelの作成
70
-
71
- private JLabel[] weekLabels = new JLabel[7];
72
-
73
- //日にちのLabelの作成
74
-
75
- private JLabel[][] dayLabels = new JLabel[6][7];
76
-
77
-
78
-
79
- //各パーツのColorの作成
80
-
81
- private static final Color WEEK_BG = new Color(102,102,102);
82
-
83
- //private static final LineBorder WEEK_BORDER = new LineBorder(new Color(160,160,230), 2, false);
84
-
85
-
86
-
87
- //日付パネルの色
88
-
89
- private static final Color DAY_BG = new Color(102,102,102);
90
-
91
- private static final Color DAY_FG = Color.BLACK;
92
-
93
- private static final LineBorder DAY_BORDER = new LineBorder(new Color(102,102,102), 2, false);
94
-
95
-
96
-
97
- //日付のLabel
98
-
99
- private static final Dimension DAY_LABEL_SIZE = new Dimension(50,50);
100
-
101
- private static final String[] WEEK_NAMES = new String[] {"日", "月", "火", "水", "木", "金", "土"};
7
+ //////////////////////////////
102
-
103
- private static final String[] MONTH_NAMES = new String[] {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
104
-
105
-
106
-
107
- public SwingCalendar() {
108
-
109
- try {
110
-
111
- UIManager.setLookAndFeel(
112
-
113
- "javax.swing.plaf.nimbus.NimbusLookAndFeel"
114
-
115
- );
116
-
117
- } catch (ClassNotFoundException | InstantiationException
118
-
119
- | IllegalAccessException | UnsupportedLookAndFeelException e) {
120
-
121
- e.printStackTrace();
122
-
123
- }
124
-
125
-
126
-
127
- /* MONTH Label */
128
-
129
- Dimension dm = monthLabel.getPreferredSize();
130
-
131
- dm.width += 10; //dm.height += 1;
132
-
133
- monthLabel.setPreferredSize(dm);
134
-
135
- monthLabel.setForeground(DAY_FG);
136
-
137
-
138
-
139
- /* YEAR Label */
140
-
141
- Dimension dy = yearLabel.getPreferredSize();
142
-
143
- dy.width += 10; //dy.height += 1;
144
-
145
- yearLabel.setPreferredSize(dy);
146
-
147
- yearLabel.setForeground(DAY_FG);
148
-
149
-
150
-
151
- /* DAY PANEL */
152
-
153
- JPanel dayPanel = new JPanel();
154
-
155
- GridLayout layout = new GridLayout(7, 7);
156
-
157
- layout.setHgap(0);
158
-
159
- layout.setVgap(0);
160
-
161
- dayPanel.setLayout(layout);
162
-
163
- dayPanel.setBackground(DAY_BG);
164
-
165
-
166
-
167
- //曜日の配列
168
-
169
- for( int i=0; i<7; i++) {
170
-
171
- weekLabels[i] = new JLabel(WEEK_NAMES[i]);
172
-
173
- weekLabels[i].setHorizontalAlignment(SwingConstants.CENTER);
174
-
175
- weekLabels[i].setVerticalAlignment(SwingConstants.CENTER);
176
-
177
- weekLabels[i].setPreferredSize(DAY_LABEL_SIZE);
178
-
179
- weekLabels[i].setOpaque(true);
180
-
181
- weekLabels[i].setBackground(WEEK_BG);
182
-
183
- //weekLabels[i].setBorder(WEEK_BORDER);
184
-
185
- if( i == 0 ) {
186
-
187
- weekLabels[i].setForeground(Color.RED);
188
-
189
- } else if ( i == 6 ) {
190
-
191
- weekLabels[i].setForeground(Color.BLUE);
192
-
193
- }
194
-
195
-
196
-
197
- System.out.println("kakunin" + i);
198
-
199
- dayPanel.add(weekLabels[i]);
200
-
201
- }
202
-
203
-
204
-
205
- //日付の配列
206
-
207
- for( int i=0; i<6; i++) {
208
-
209
- for( int j=0; j<7; j++) {
210
-
211
- dayLabels[i][j] = new JLabel(); //String.valueOf(i),(j)
212
-
213
- dayLabels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
214
-
215
- dayLabels[i][j].setVerticalAlignment(SwingConstants.CENTER);
216
-
217
- dayLabels[i][j].setOpaque(true);
218
-
219
- dayLabels[i][j].setBackground(DAY_BG);
220
-
221
- dayLabels[i][j].setPreferredSize(DAY_LABEL_SIZE);
222
-
223
- //dayLabels[i][j].setBorder(new LineBorder(Color.DARK_GRAY, 2, false));
224
-
225
- System.out.println("i" + i); //確認
226
-
227
- System.out.println("j" + j); //確認
228
-
229
-
230
-
231
- //dayLabels[i][j].setForeground(Color.WHITE);
232
-
233
- //String t = Integer.toString((i),(j));
234
-
235
-
236
-
237
- if( i == 0 && j == 0 ) {
238
-
239
- dayLabels[i][j].setForeground(Color.RED);
240
-
241
- } else if ( i == 6 && j == 0 ) {
242
-
243
- dayLabels[i][j].setForeground(Color.BLUE);
244
-
245
- }
246
-
247
-
248
-
249
- dayPanel.add(dayLabels[i][j]);
250
-
251
- }
252
-
253
-
254
-
255
- }
256
-
257
-
258
-
259
- JPanel monthPanel = new JPanel();
260
-
261
- monthPanel.setLayout(new GridLayout());
262
-
263
- monthPanel.add(yearLabel);
264
-
265
- monthPanel.add(monthLabel);
266
-
267
- monthPanel.setBackground(DAY_BG);
268
-
269
-
270
-
271
- setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
272
-
273
- GridLayout gl = new GridLayout(1,2);
274
-
275
- gl.setHgap(10); gl.setVgap(10);
276
-
277
-
278
-
279
- //年月ボタン表示パネル、日にちパネルの追加
280
-
281
- add(monthPanel);
282
-
283
- add(dayPanel);
284
-
285
-
286
-
287
- }
288
-
289
-
290
-
291
- }
292
-
293
-
294
-
295
- 前提・実現したいこと
296
-
297
- 日付(土日祝)の色の変更をしたいのですがうまくいきません。
298
8
 
299
9
  ```

2

///

2018/08/17 01:34

投稿

shuriboo
shuriboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ``````java
1
+ ```Java
2
2
 
3
3
  import java.awt.Color;
4
4
 
@@ -30,290 +30,270 @@
30
30
 
31
31
  public class debugTest {
32
32
 
33
- public static void main(String[] args) {
33
+ public static void main(String[] args) {
34
-
34
+
35
- JFrame frame = new JFrame("Swing Calender");
35
+ JFrame frame = new JFrame("Swing Calender");
36
36
 
37
37
  // frame.setSize(400,600);
38
38
 
39
- frame.add(new SwingCalendar());
39
+ frame.add(new SwingCalendar());
40
-
40
+
41
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
41
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42
-
42
+
43
- frame.pack();
43
+ frame.pack();
44
-
44
+
45
- frame.setVisible(true);
45
+ frame.setVisible(true);
46
-
46
+
47
- }
47
+ }
48
-
48
+
49
- }
49
+ }
50
-
51
-
52
50
 
53
51
 
54
52
 
55
53
  class SwingCalendar extends JPanel {
56
54
 
57
- //月のLabelの宣言
58
-
59
- private JLabel monthLabel = new JLabel();
60
-
61
- //年のLabelの宣言
62
-
63
- private JLabel yearLabel = new JLabel();
64
-
65
- //Calendarクラスのインスタンス化取得
66
-
67
- Calendar cal = Calendar.getInstance();
68
-
69
-
70
-
71
-
72
-
73
- //曜日のLabelの作成
74
-
75
- private JLabel[] weekLabels = new JLabel[7];
76
-
77
- //日にちのLabelの作成
78
-
79
- private JLabel[][] dayLabels = new JLabel[6][7];
80
-
81
-
82
-
83
- //各パーツのColorの作成
84
-
85
- private static final Color WEEK_BG = new Color(102,102,102);
86
-
87
- //private static final LineBorder WEEK_BORDER = new LineBorder(new Color(160,160,230), 2, false);
88
-
89
-
90
-
91
- //日付パネルの色
92
-
93
- private static final Color DAY_BG = new Color(102,102,102);
94
-
95
- private static final Color DAY_FG = Color.BLACK;
96
-
97
- private static final LineBorder DAY_BORDER = new LineBorder(new Color(102,102,102), 2, false);
98
-
99
-
100
-
101
- //日付のLabel
102
-
103
- private static final Dimension DAY_LABEL_SIZE = new Dimension(50,50);
104
-
105
- private static final String[] WEEK_NAMES = new String[] {"", "月", "", "", "", "", ""};
106
-
107
- private static final String[] MONTH_NAMES = new String[] {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
108
-
109
-
110
-
111
- public SwingCalendar() {
112
-
113
- try {
114
-
115
- UIManager.setLookAndFeel(
116
-
117
- "javax.swing.plaf.nimbus.NimbusLookAndFeel"
118
-
119
- );
120
-
121
- } catch (ClassNotFoundException | InstantiationException
122
-
123
- | IllegalAccessException | UnsupportedLookAndFeelException e) {
124
-
125
- e.printStackTrace();
126
-
127
- }
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
- /* MONTH Label */
136
-
137
- Dimension dm = monthLabel.getPreferredSize();
138
-
139
- dm.width += 10; //dm.height += 1;
140
-
141
- monthLabel.setPreferredSize(dm);
142
-
143
- monthLabel.setForeground(DAY_FG);
144
-
145
-
146
-
147
- /* YEAR Label */
148
-
149
- Dimension dy = yearLabel.getPreferredSize();
150
-
151
- dy.width += 10; //dy.height += 1;
152
-
153
- yearLabel.setPreferredSize(dy);
154
-
155
- yearLabel.setForeground(DAY_FG);
156
-
157
-
158
-
159
- /* DAY PANEL */
160
-
161
- JPanel dayPanel = new JPanel();
162
-
163
- GridLayout layout = new GridLayout(7, 7);
164
-
165
- layout.setHgap(0);
166
-
167
- layout.setVgap(0);
168
-
169
- dayPanel.setLayout(layout);
170
-
171
- dayPanel.setBackground(DAY_BG);
172
-
173
-
174
-
175
- //曜日の配列
176
-
177
- for( int i=0; i<7; i++) {
178
-
179
- weekLabels[i] = new JLabel(WEEK_NAMES[i]);
180
-
181
- weekLabels[i].setHorizontalAlignment(SwingConstants.CENTER);
182
-
183
- weekLabels[i].setVerticalAlignment(SwingConstants.CENTER);
184
-
185
- weekLabels[i].setPreferredSize(DAY_LABEL_SIZE);
186
-
187
- weekLabels[i].setOpaque(true);
188
-
189
- weekLabels[i].setBackground(WEEK_BG);
190
-
191
- //weekLabels[i].setBorder(WEEK_BORDER);
192
-
193
- if( i == 0 ) {
194
-
195
- weekLabels[i].setForeground(Color.RED);
196
-
197
- } else if ( i == 6 ) {
198
-
199
- weekLabels[i].setForeground(Color.BLUE);
200
-
201
- }
202
-
203
-
204
-
205
- System.out.println("kakunin" + i);
206
-
207
- dayPanel.add(weekLabels[i]);
208
-
209
- }
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
- //日付の配列
218
-
219
- for( int i=0; i<6; i++) {
220
-
221
- for( int j=0; j<7; j++) {
222
-
223
- dayLabels[i][j] = new JLabel(); //String.valueOf(i),(j)
224
-
225
- dayLabels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
226
-
227
- dayLabels[i][j].setVerticalAlignment(SwingConstants.CENTER);
228
-
229
- dayLabels[i][j].setOpaque(true);
230
-
231
- dayLabels[i][j].setBackground(DAY_BG);
232
-
233
- dayLabels[i][j].setPreferredSize(DAY_LABEL_SIZE);
234
-
235
- //dayLabels[i][j].setBorder(new LineBorder(Color.DARK_GRAY, 2, false));
236
-
237
- System.out.println("i" + i); //確認
238
-
239
- System.out.println("j" + j); //確認
240
-
241
-
242
-
243
- //dayLabels[i][j].setForeground(Color.WHITE);
244
-
245
- //String t = Integer.toString((i),(j));
246
-
247
-
248
-
249
-
250
-
251
- if( i == 0 && j == 0 ) {
252
-
253
- dayLabels[i][j].setForeground(Color.RED);
254
-
255
- } else if ( i == 6 && j == 0 ) {
256
-
257
- dayLabels[i][j].setForeground(Color.BLUE);
258
-
259
- }
260
-
261
-
262
-
263
- dayPanel.add(dayLabels[i][j]);
264
-
265
- }
266
-
267
-
268
-
269
- }
270
-
271
-
272
-
273
-
274
-
275
- JPanel monthPanel = new JPanel();
276
-
277
- monthPanel.setLayout(new GridLayout());
278
-
279
- monthPanel.add(yearLabel);
280
-
281
- monthPanel.add(monthLabel);
282
-
283
- monthPanel.setBackground(DAY_BG);
284
-
285
-
286
-
287
-
288
-
289
- setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
290
-
291
- GridLayout gl = new GridLayout(1,2);
292
-
293
- gl.setHgap(10); gl.setVgap(10);
294
-
295
-
296
-
297
-
298
-
299
- //年月ボタン表示パネル、日にちパネルの追加
300
-
301
- add(monthPanel);
302
-
303
- add(dayPanel);
304
-
305
-
306
-
307
- }
308
-
309
-
310
-
311
- }
312
-
313
-
55
+ //月のLabelの宣言
56
+
57
+ private JLabel monthLabel = new JLabel();
58
+
59
+ //年のLabelの宣言
60
+
61
+ private JLabel yearLabel = new JLabel();
62
+
63
+ //Calendarクラスのインスタンス化取得
64
+
65
+ Calendar cal = Calendar.getInstance();
66
+
67
+
68
+
69
+ //曜日のLabelの作成
70
+
71
+ private JLabel[] weekLabels = new JLabel[7];
72
+
73
+ //日にちのLabelの作成
74
+
75
+ private JLabel[][] dayLabels = new JLabel[6][7];
76
+
77
+
78
+
79
+ //各パーツのColorの作成
80
+
81
+ private static final Color WEEK_BG = new Color(102,102,102);
82
+
83
+ //private static final LineBorder WEEK_BORDER = new LineBorder(new Color(160,160,230), 2, false);
84
+
85
+
86
+
87
+ //日付パネルの色
88
+
89
+ private static final Color DAY_BG = new Color(102,102,102);
90
+
91
+ private static final Color DAY_FG = Color.BLACK;
92
+
93
+ private static final LineBorder DAY_BORDER = new LineBorder(new Color(102,102,102), 2, false);
94
+
95
+
96
+
97
+ //日付のLabel
98
+
99
+ private static final Dimension DAY_LABEL_SIZE = new Dimension(50,50);
100
+
101
+ private static final String[] WEEK_NAMES = new String[] {"日", "月", "火", "水", "木", "金", "土"};
102
+
103
+ private static final String[] MONTH_NAMES = new String[] {"1月", "月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
104
+
105
+
106
+
107
+ public SwingCalendar() {
108
+
109
+ try {
110
+
111
+ UIManager.setLookAndFeel(
112
+
113
+ "javax.swing.plaf.nimbus.NimbusLookAndFeel"
114
+
115
+ );
116
+
117
+ } catch (ClassNotFoundException | InstantiationException
118
+
119
+ | IllegalAccessException | UnsupportedLookAndFeelException e) {
120
+
121
+ e.printStackTrace();
122
+
123
+ }
124
+
125
+
126
+
127
+ /* MONTH Label */
128
+
129
+ Dimension dm = monthLabel.getPreferredSize();
130
+
131
+ dm.width += 10; //dm.height += 1;
132
+
133
+ monthLabel.setPreferredSize(dm);
134
+
135
+ monthLabel.setForeground(DAY_FG);
136
+
137
+
138
+
139
+ /* YEAR Label */
140
+
141
+ Dimension dy = yearLabel.getPreferredSize();
142
+
143
+ dy.width += 10; //dy.height += 1;
144
+
145
+ yearLabel.setPreferredSize(dy);
146
+
147
+ yearLabel.setForeground(DAY_FG);
148
+
149
+
150
+
151
+ /* DAY PANEL */
152
+
153
+ JPanel dayPanel = new JPanel();
154
+
155
+ GridLayout layout = new GridLayout(7, 7);
156
+
157
+ layout.setHgap(0);
158
+
159
+ layout.setVgap(0);
160
+
161
+ dayPanel.setLayout(layout);
162
+
163
+ dayPanel.setBackground(DAY_BG);
164
+
165
+
166
+
167
+ //曜日の配列
168
+
169
+ for( int i=0; i<7; i++) {
170
+
171
+ weekLabels[i] = new JLabel(WEEK_NAMES[i]);
172
+
173
+ weekLabels[i].setHorizontalAlignment(SwingConstants.CENTER);
174
+
175
+ weekLabels[i].setVerticalAlignment(SwingConstants.CENTER);
176
+
177
+ weekLabels[i].setPreferredSize(DAY_LABEL_SIZE);
178
+
179
+ weekLabels[i].setOpaque(true);
180
+
181
+ weekLabels[i].setBackground(WEEK_BG);
182
+
183
+ //weekLabels[i].setBorder(WEEK_BORDER);
184
+
185
+ if( i == 0 ) {
186
+
187
+ weekLabels[i].setForeground(Color.RED);
188
+
189
+ } else if ( i == 6 ) {
190
+
191
+ weekLabels[i].setForeground(Color.BLUE);
192
+
193
+ }
194
+
195
+
196
+
197
+ System.out.println("kakunin" + i);
198
+
199
+ dayPanel.add(weekLabels[i]);
200
+
201
+ }
202
+
203
+
204
+
205
+ //日付の配列
206
+
207
+ for( int i=0; i<6; i++) {
208
+
209
+ for( int j=0; j<7; j++) {
210
+
211
+ dayLabels[i][j] = new JLabel(); //String.valueOf(i),(j)
212
+
213
+ dayLabels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
214
+
215
+ dayLabels[i][j].setVerticalAlignment(SwingConstants.CENTER);
216
+
217
+ dayLabels[i][j].setOpaque(true);
218
+
219
+ dayLabels[i][j].setBackground(DAY_BG);
220
+
221
+ dayLabels[i][j].setPreferredSize(DAY_LABEL_SIZE);
222
+
223
+ //dayLabels[i][j].setBorder(new LineBorder(Color.DARK_GRAY, 2, false));
224
+
225
+ System.out.println("i" + i); //確認
226
+
227
+ System.out.println("j" + j); //確認
228
+
229
+
230
+
231
+ //dayLabels[i][j].setForeground(Color.WHITE);
232
+
233
+ //String t = Integer.toString((i),(j));
234
+
235
+
236
+
237
+ if( i == 0 && j == 0 ) {
238
+
239
+ dayLabels[i][j].setForeground(Color.RED);
240
+
241
+ } else if ( i == 6 && j == 0 ) {
242
+
243
+ dayLabels[i][j].setForeground(Color.BLUE);
244
+
245
+ }
246
+
247
+
248
+
249
+ dayPanel.add(dayLabels[i][j]);
250
+
251
+ }
252
+
253
+
254
+
255
+ }
256
+
257
+
258
+
259
+ JPanel monthPanel = new JPanel();
260
+
261
+ monthPanel.setLayout(new GridLayout());
262
+
263
+ monthPanel.add(yearLabel);
264
+
265
+ monthPanel.add(monthLabel);
266
+
267
+ monthPanel.setBackground(DAY_BG);
268
+
269
+
270
+
271
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
272
+
273
+ GridLayout gl = new GridLayout(1,2);
274
+
275
+ gl.setHgap(10); gl.setVgap(10);
276
+
277
+
278
+
279
+ //年月ボタン表示パネル、日にちパネルの追加
280
+
281
+ add(monthPanel);
282
+
283
+ add(dayPanel);
284
+
285
+
286
+
287
+ }
288
+
289
+
290
+
291
+ }
314
292
 
315
293
 
316
294
 
317
295
  前提・実現したいこと
318
296
 
319
297
  日付(土日祝)の色の変更をしたいのですがうまくいきません。
298
+
299
+ ```

1

///

2018/08/16 10:29

投稿

shuriboo
shuriboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -309,3 +309,11 @@
309
309
 
310
310
 
311
311
  }
312
+
313
+
314
+
315
+
316
+
317
+ 前提・実現したいこと
318
+
319
+ 日付(土日祝)の色の変更をしたいのですがうまくいきません。