0
マウスイベントを受け付けてくれない
マウスイベントを受け付けてくれないのですがどこが間違っているのでしょうか?ご教授していただけると助かります。
public class GamePanel extends JPanel implements Runnable, MouseListener {
// 画面サイズを指定
private static final int width = 640;
private static final int height = 480;
// パス・区分クラス
Path_KBN pk;
// テキスト読み込みリスト
ArrayList<String> textList;
// スプライトクラス
Sprite sp;
// ゲームスレッド
Thread gameloop;
// テキスト表示ようビルダー
String[] viewText;
// ゲームフラグ
int gameFlag = 0;
// テキスト行カウンタ
int count = 0;
public GamePanel() throws IOException, FileNotFoundException {
// 画面サイズ
setPreferredSize(new Dimension(width, height));
// パス・区分クラス生成
pk = new Path_KBN();
// テキストリスト生成
textList = new ArrayList<String>();
// テキスト読み込み
loadText(pk.START);
// テキスト保持生成
viewText = new String[10];
for (int i = 0; i < 10; i++) {
viewText[i] = "";
}
// パネルがキー入力を受け付けるようにする
setFocusable(true);
// スプライトクラス生成
sp = new Sprite();
// プール・スプライトの初期化
initSprite();
// ゲームスレッド生成と開始
gameloop = new Thread(this);
gameloop.start();
}
public void run() {
while (true) {
System.out.println(count);
// 再描画する
repaint();
// 長めに停止
try {
Thread.sleep(100);
} catch (Exception e) {
System.out.println("スレッド停止時のExcepionです。");
}
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
// スプライトを順番に描画する
for (int i = 0; i < 11; i++) {
g.drawImage(sp.sprite.get(i), 0, 0, null);
}
// テキストの描画
if (viewText[1] == "") {
for (int i = 0; i < 10; i++) {
if (viewText[i] == "") {
g.setColor(Color.BLACK);
g.drawString(viewText[1], 5, (i * 22) + 23);
g.setColor(Color.WHITE);
g.drawString(viewText[i], 5, (i * 22) + 22);
}
}
}
}
public void loadText(String URL) throws IOException, FileNotFoundException {
textList.clear();
File text = new File(URL);
BufferedReader br = new BufferedReader(new FileReader(text));
String line;
while ((line = br.readLine()) != null) {
textList.add(line);
}
}
public void mouseClicked(MouseEvent e) {
System.out.println("A");
}
public void mouseEntered(MouseEvent e) {
System.out.println("B");
}
public void mouseExited(MouseEvent e) {
System.out.println("C");
}
public void mousePressed(MouseEvent e) {
System.out.println("D");
}
public void mouseReleased(MouseEvent e) {
System.out.println("E");
}
private void initSprite(){
sp.setPool(pk.P_MU, pk.G_MU);
sp.setPool(pk.P_TITLE, pk.G_TITLE);
for (int i = 0; i < 10; i++) {
sp.setSprite(i, pk.P_MU);
}
sp.setSprite(pk.S_TITLE, pk.P_TITLE);
}
}