単刀直入に言います。
Swingで三角錐の展開図を表示はできているのですが、表示した三角形の中に数字("1","2","3","4")で色を区別することはできるのでしょうか?
数字としては、("1→赤色","2→青色","3→緑色","4→黄色")と反映させたいです。
わかる方からの返答お待ちしています。
ソースは以下になります。
java
1import javax.swing.JFrame; 2import java.awt.Color; 3import java.awt.Graphics; 4 5public class takakkei_1 extends JFrame{ 6 7 8 9 public static void main(String[] args) { 10 takakkei_1 frame = new takakkei_1(); 11 frame.setVisible(true); 12 frame.setBounds(200, 200, 800, 600); 13 14 } 15 16 public void paint(Graphics g){ 17 /* 小さい三角一個を(x:60,y:60)の大きさ*/ 18 19 /* 一面 */ 20 int x1[] = {425,395,455,425}; 21 int y1[] = {510,450,450,510}; 22 23 int x2[] = {365,395,425,365}; 24 int y2[] = {390,450,390,390}; 25 26 int x3[] = {395,425,455,395}; 27 int y3[] = {450,390,450,450}; 28 29 int x4[] = {425,455,485,425}; 30 int y4[] = {390,450,390,390}; 31 32 int x5[] = {335,365,395,335}; 33 int y5[] = {330,390,330,330}; 34 35 int x6[] = {365,395,425,365}; 36 int y6[] = {390,330,390,390}; 37 38 int x7[] = {395,425,455,395}; 39 int y7[] = {330,390,330,330}; 40 41 int x8[] = {425,455,485,425}; 42 int y8[] = {390,330,390,390}; 43 44 int x9[] = {455,485,515,455}; 45 int y9[] = {330,390,330,330}; 46 /*二面*/ 47 int x10[] = {335,365,395,335}; 48 int y10[] = {330,270,330,330}; 49 50 int x11[] = {365,395,425,365}; 51 int y11[] = {270,330,270,270}; 52 53 int x12[] = {395,425,455,395}; 54 int y12[] = {330,270,330,330}; 55 56 int x13[] = {425,455,485,425}; 57 int y13[] = {270,330,270,270}; 58 59 int x14[] = {455,485,515,455}; 60 int y14[] = {330,270,330,330}; 61 62 int x15[] = {365,395,425,365}; 63 int y15[] = {270,210,270,270}; 64 65 int x16[] = {395,425,455,395}; 66 int y16[] = {210,270,210,210}; 67 68 int x17[] = {425,455,485,425}; 69 int y17[] = {270,210,270,270}; 70 71 int x18[] = {395,425,455,395}; 72 int y18[] = {210,150,210,210}; 73 /*三面*/ 74 int x19[] = {515,485,545,515}; 75 int y19[] = {330,390,390,330}; 76 77 int x20[] = {485,515,545,485}; 78 int y20[] = {390,450,390,390}; 79 80 int x21[] = {455,485,515,455}; 81 int y21[] = {450,390,450,450}; 82 83 int x22[] = {455,485,515,455}; 84 int y22[] = {450,510,450,450}; 85 86 int x23[] = {425,455,485,425}; 87 int y23[] = {510,450,510,510}; 88 89 int x24[] = {515,545,575,515}; 90 int y24[] = {450,390,450,450}; 91 92 int x25[] = {515,545,575,515}; 93 int y25[] = {450,510,450,450}; 94 95 int x26[] = {485,515,545,485}; 96 int y26[] = {510,450,510,510}; 97 98 int x27[] = {545,575,605,545}; 99 int y27[] = {510,450,510,510}; 100 /*四面*/ 101 int x28[] = {395,365,425,395}; 102 int y28[] = {450,510,510,450}; 103 104 int x29[] = {335,365,395,335}; 105 int y29[] = {450,510,450,450}; 106 107 int x30[] = {335,365,395,335}; 108 int y30[] = {450,390,450,450}; 109 110 int x31[] = {305,335,365,305}; 111 int y31[] = {390,450,390,390}; 112 113 int x32[] = {305,335,365,305}; 114 int y32[] = {390,330,390,390}; 115 116 int x33[] = {275,305,335,275}; 117 int y33[] = {450,390,450,450}; 118 119 int x34[] = {275,305,335,275}; 120 int y34[] = {450,510,450,450}; 121 122 int x35[] = {305,335,365,305}; 123 int y35[] = {510,450,510,510}; 124 125 int x36[] = {245,275,305,245}; 126 int y36[] = {510,450,510,510}; 127 128 /*1面*/ 129 g.setColor(Color.RED); 130 g.fillPolygon(x1, y1, 4); 131 132 g.setColor(Color.GREEN); 133 g.fillPolygon(x2, y2, 4); 134 135 g.setColor(Color.BLUE); 136 g.fillPolygon(x3, y3, 4); 137 138 g.setColor(Color.YELLOW); 139 g.fillPolygon(x4, y4, 4); 140 141 g.setColor(Color.RED); 142 g.fillPolygon(x5, y5, 4); 143 144 g.setColor(Color.BLUE); 145 g.fillPolygon(x6, y6, 4); 146 147 g.setColor(Color.GREEN); 148 g.fillPolygon(x7, y7, 4); 149 150 g.setColor(Color.RED); 151 g.fillPolygon(x8, y8, 4); 152 153 g.setColor(Color.BLUE); 154 g.fillPolygon(x9, y9, 4); 155 156 /*2面*/ 157 g.setColor(Color.YELLOW); 158 g.fillPolygon(x10, y10, 4); 159 160 g.setColor(Color.GREEN); 161 g.fillPolygon(x11, y11, 4); 162 163 g.setColor(Color.BLUE); 164 g.fillPolygon(x12, y12, 4); 165 166 g.setColor(Color.YELLOW); 167 g.fillPolygon(x13, y13, 4); 168 169 g.setColor(Color.RED); 170 g.fillPolygon(x14, y14, 4); 171 172 g.setColor(Color.BLUE); 173 g.fillPolygon(x15, y15, 4); 174 175 g.setColor(Color.GREEN); 176 g.fillPolygon(x16, y16, 4); 177 178 g.setColor(Color.RED); 179 g.fillPolygon(x17, y17, 4); 180 181 g.setColor(Color.BLUE); 182 g.fillPolygon(x18, y18, 4); 183 184 /*3面*/ 185 g.setColor(Color.RED); 186 g.fillPolygon(x19, y19, 4); 187 188 g.setColor(Color.GREEN); 189 g.fillPolygon(x20, y20, 4); 190 191 g.setColor(Color.BLUE); 192 g.fillPolygon(x21, y21, 4); 193 194 g.setColor(Color.YELLOW); 195 g.fillPolygon(x22, y22, 4); 196 197 g.setColor(Color.GREEN); 198 g.fillPolygon(x23, y23, 4); 199 200 g.setColor(Color.BLUE); 201 g.fillPolygon(x24, y24, 4); 202 203 g.setColor(Color.GREEN); 204 g.fillPolygon(x25, y25, 4); 205 206 g.setColor(Color.RED); 207 g.fillPolygon(x26, y26, 4); 208 209 g.setColor(Color.BLUE); 210 g.fillPolygon(x27, y27, 4); 211 /*4面*/ 212 g.setColor(Color.BLUE); 213 g.fillPolygon(x28, y28, 4); 214 215 g.setColor(Color.GREEN); 216 g.fillPolygon(x29, y29, 4); 217 218 g.setColor(Color.BLUE); 219 g.fillPolygon(x30, y30, 4); 220 221 g.setColor(Color.YELLOW); 222 g.fillPolygon(x31, y31, 4); 223 224 g.setColor(Color.GREEN); 225 g.fillPolygon(x32, y32, 4); 226 227 g.setColor(Color.BLUE); 228 g.fillPolygon(x33, y33, 4); 229 230 g.setColor(Color.GREEN); 231 g.fillPolygon(x34, y34, 4); 232 233 g.setColor(Color.RED); 234 g.fillPolygon(x35, y35, 4); 235 236 g.setColor(Color.BLUE); 237 g.fillPolygon(x36, y36, 4); 238 } 239 240 takakkei_1(){ 241 242 } 243}
となっています。