回答編集履歴
2
imageFiles,randomTable をパラメータ化
test
CHANGED
@@ -44,6 +44,12 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
+
private final String imageFiles[]={ "しーん.jpg", "!.jpg", "!!.jpg", "!!!.jpg", "?.jpg" };
|
48
|
+
|
49
|
+
private final int randomTable[]={1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4};
|
50
|
+
|
51
|
+
|
52
|
+
|
47
53
|
// ゲーム画面
|
48
54
|
|
49
55
|
public Fishing(){
|
@@ -56,7 +62,7 @@
|
|
56
62
|
|
57
63
|
|
58
64
|
|
59
|
-
ButtonAction buttonAction = new ButtonAction();
|
65
|
+
ButtonAction buttonAction = new ButtonAction(imageFiles, randomTable);
|
60
66
|
|
61
67
|
|
62
68
|
|
@@ -80,9 +86,9 @@
|
|
80
86
|
|
81
87
|
|
82
88
|
|
83
|
-
public void onClick(int
|
89
|
+
public void onClick(int imageNumber) {
|
84
90
|
|
85
|
-
System.out.println("ボタンが押された.
|
91
|
+
System.out.println("'"+imageFiles[imageNumber]+"' ボタンが押された. (imageNumber="+imageNumber+")");
|
86
92
|
|
87
93
|
}
|
88
94
|
|
@@ -90,21 +96,19 @@
|
|
90
96
|
|
91
97
|
private class ButtonAction extends AbstractAction {
|
92
98
|
|
93
|
-
private final String imageFiles[] ={ "しーん.jpg", "!.jpg", "!!.jpg", "!!!.jpg", "?.jpg" };
|
94
|
-
|
95
99
|
private ImageIcon buttonImages[];
|
96
100
|
|
97
|
-
private int
|
101
|
+
private int imageNumber;
|
98
102
|
|
99
103
|
|
100
104
|
|
101
|
-
private
|
105
|
+
private int randomTable[];
|
102
106
|
|
103
107
|
private Random random = new Random();
|
104
108
|
|
105
109
|
|
106
110
|
|
107
|
-
ButtonAction() {
|
111
|
+
ButtonAction(String imageFiles[], int randomTable[]) {
|
108
112
|
|
109
113
|
buttonImages = new ImageIcon[imageFiles.length];
|
110
114
|
|
@@ -114,13 +118,15 @@
|
|
114
118
|
|
115
119
|
}
|
116
120
|
|
121
|
+
this.randomTable = randomTable;
|
122
|
+
|
117
123
|
putImage(0);
|
118
124
|
|
119
125
|
}
|
120
126
|
|
121
127
|
private void putImage(int number) {
|
122
128
|
|
123
|
-
|
129
|
+
imageNumber = number;
|
124
130
|
|
125
131
|
putValue(Action.LARGE_ICON_KEY, buttonImages[number]);
|
126
132
|
|
@@ -152,7 +158,7 @@
|
|
152
158
|
|
153
159
|
public void actionPerformed(ActionEvent e) {
|
154
160
|
|
155
|
-
onClick(
|
161
|
+
onClick(imageNumber);
|
156
162
|
|
157
163
|
}
|
158
164
|
|
1
コード修正
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
private class ButtonAction extends AbstractAction {
|
92
92
|
|
93
|
-
private String imageFiles[] ={ "しーん.jpg", "!.jpg", "!!.jpg", "!!!.jpg", "?.jpg" };
|
93
|
+
private final String imageFiles[] ={ "しーん.jpg", "!.jpg", "!!.jpg", "!!!.jpg", "?.jpg" };
|
94
94
|
|
95
95
|
private ImageIcon buttonImages[];
|
96
96
|
|
@@ -144,7 +144,7 @@
|
|
144
144
|
|
145
145
|
timer.setRepeats(false);
|
146
146
|
|
147
|
-
timer.
|
147
|
+
timer.start();
|
148
148
|
|
149
149
|
}
|
150
150
|
|