質問編集履歴
3
コメントの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,86 +110,88 @@
|
|
110
110
|
|
111
111
|
timer = new Timer(1000 / FPS, this);
|
112
112
|
|
113
|
+
back = createImage(this.getWidth(), this.getHeight());//バッファイメージ
|
114
|
+
|
115
|
+
buffer = back.getGraphics();//イメージのグラフィクス
|
116
|
+
|
117
|
+
titleImage = MyUtilities.getImage("../images/title/TitleImage.jpg");
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
timer.start();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
@Override
|
128
|
+
|
129
|
+
public void paint(Graphics graphics){
|
130
|
+
|
131
|
+
if(buffer != null){
|
132
|
+
|
133
|
+
//イメージの更新、描画
|
134
|
+
|
135
|
+
buffer.clearRect(0, 0, this.getWidth(), this.getHeight());
|
136
|
+
|
137
|
+
buffer.drawImage(titleImage, 0, 0, this.getWidth(), this.getHeight(), null);
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
graphics.drawImage(back, 0, 0, this);
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
@Override
|
150
|
+
|
151
|
+
public void actionPerformed(ActionEvent e){
|
152
|
+
|
153
|
+
Object source = e.getSource();
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
if(source == timer){
|
158
|
+
|
159
|
+
timeMeasure.Update();
|
160
|
+
|
161
|
+
repaint();//再描画
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
@Override
|
170
|
+
|
171
|
+
public void componentHidden(ComponentEvent e) {}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
@Override
|
176
|
+
|
177
|
+
public void componentMoved(ComponentEvent e) {}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
@Override//リサイズしたとき
|
182
|
+
|
183
|
+
public void componentResized(ComponentEvent e) {
|
184
|
+
|
113
185
|
back = createImage(this.getWidth(), this.getHeight());
|
114
186
|
|
115
187
|
buffer = back.getGraphics();
|
116
188
|
|
117
|
-
titleImage = MyUtilities.getImage("../images/title/TitleImage.jpg");
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
timer.start();
|
122
|
-
|
123
|
-
}
|
189
|
+
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@Override
|
128
|
-
|
129
|
-
public void paint(Graphics graphics){
|
130
|
-
|
131
|
-
if(buffer != null){
|
132
|
-
|
133
|
-
buffer.clearRect(0, 0, this.getWidth(), this.getHeight());
|
134
|
-
|
135
|
-
buffer.drawImage(titleImage, 0, 0, this.getWidth(), this.getHeight(), null);
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
graphics.drawImage(back, 0, 0, this);
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
@Override
|
148
|
-
|
149
|
-
public void actionPerformed(ActionEvent e){
|
150
|
-
|
151
|
-
Object source = e.getSource();
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
if(source == timer){
|
156
|
-
|
157
|
-
timeMeasure.Update();
|
158
|
-
|
159
|
-
repaint();
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@Override
|
168
|
-
|
169
|
-
public void componentHidden(ComponentEvent e) {}
|
170
190
|
|
171
191
|
|
172
192
|
|
173
193
|
@Override
|
174
194
|
|
175
|
-
public void componentMoved(ComponentEvent e) {}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
@Override
|
180
|
-
|
181
|
-
public void componentResized(ComponentEvent e) {
|
182
|
-
|
183
|
-
back = createImage(this.getWidth(), this.getHeight());
|
184
|
-
|
185
|
-
buffer = back.getGraphics();
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@Override
|
192
|
-
|
193
195
|
public void componentShown(ComponentEvent e) {}
|
194
196
|
|
195
197
|
}
|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,6 +36,168 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
#修正(該当のコード)
|
40
|
+
|
41
|
+
```java
|
42
|
+
|
43
|
+
package orgmarigo.test;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
import javax.swing.*;
|
48
|
+
|
49
|
+
import java.awt.Graphics;
|
50
|
+
|
51
|
+
import java.awt.Image;
|
52
|
+
|
53
|
+
import java.awt.event.*;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
import orgmarigo.util.Vector2;
|
58
|
+
|
59
|
+
import orgmarigo.util.TimeMeasure;//フレームレートを測定するクラス
|
60
|
+
|
61
|
+
import orgmarigo.util.MyUtilities;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
public class ScreenTest extends JFrame implements ActionListener, ComponentListener{
|
66
|
+
|
67
|
+
static public final Vector2 INITIAL_WINDOW_SIZE = new Vector2(630, 560);
|
68
|
+
|
69
|
+
static public TimeMeasure timeMeasure = new TimeMeasure(100);
|
70
|
+
|
71
|
+
static public final int FPS = 100;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
private Timer timer;
|
76
|
+
|
77
|
+
private Image back;
|
78
|
+
|
79
|
+
private Graphics buffer;
|
80
|
+
|
81
|
+
private Image titleImage;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public static void main(String[] args) {
|
86
|
+
|
87
|
+
new ScreenTest();
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
public ScreenTest(){
|
94
|
+
|
95
|
+
this.setTitle("ScreenTest");
|
96
|
+
|
97
|
+
this.setBounds(300, 200, (int)INITIAL_WINDOW_SIZE.getX(), (int)INITIAL_WINDOW_SIZE.getY());
|
98
|
+
|
99
|
+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
this.addComponentListener(this);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
this.setVisible(true);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
timer = new Timer(1000 / FPS, this);
|
112
|
+
|
113
|
+
back = createImage(this.getWidth(), this.getHeight());
|
114
|
+
|
115
|
+
buffer = back.getGraphics();
|
116
|
+
|
117
|
+
titleImage = MyUtilities.getImage("../images/title/TitleImage.jpg");
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
timer.start();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
@Override
|
128
|
+
|
129
|
+
public void paint(Graphics graphics){
|
130
|
+
|
131
|
+
if(buffer != null){
|
132
|
+
|
133
|
+
buffer.clearRect(0, 0, this.getWidth(), this.getHeight());
|
134
|
+
|
135
|
+
buffer.drawImage(titleImage, 0, 0, this.getWidth(), this.getHeight(), null);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
graphics.drawImage(back, 0, 0, this);
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
@Override
|
148
|
+
|
149
|
+
public void actionPerformed(ActionEvent e){
|
150
|
+
|
151
|
+
Object source = e.getSource();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
if(source == timer){
|
156
|
+
|
157
|
+
timeMeasure.Update();
|
158
|
+
|
159
|
+
repaint();
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
@Override
|
168
|
+
|
169
|
+
public void componentHidden(ComponentEvent e) {}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
@Override
|
174
|
+
|
175
|
+
public void componentMoved(ComponentEvent e) {}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
@Override
|
180
|
+
|
181
|
+
public void componentResized(ComponentEvent e) {
|
182
|
+
|
183
|
+
back = createImage(this.getWidth(), this.getHeight());
|
184
|
+
|
185
|
+
buffer = back.getGraphics();
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
@Override
|
192
|
+
|
193
|
+
public void componentShown(ComponentEvent e) {}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
|
39
201
|
#その他
|
40
202
|
|
41
203
|
・ネットで調べて、setDoubleBuffered(boolean)を見つけたが使い方がわからなかった。
|
1
追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ダブルバッファリング
|
1
|
+
ダブルバッファリングしたら重くなりました
|
test
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
|
24
|
+
|
23
25
|
#問題点
|
24
26
|
|
25
27
|
・実行してみて、画面を大きくすると動きが遅くなることに気がついた。
|
@@ -30,6 +32,8 @@
|
|
30
32
|
|
31
33
|
・試しに、**paint(Graphics g)**において、先頭で**buffer = g;**を書くと(ダブルバッファリングしないようにすると)ちらつくが速くなった。
|
32
34
|
|
35
|
+
・試しに、インスタンス生成時に**createImage(2000, 2000)**とするとずっと遅くなった。
|
36
|
+
|
33
37
|
|
34
38
|
|
35
39
|
#その他
|