Java 2D グラフィックスは初めてで、mouseclick イベントの処理に問題があります。マウスのステータスを clicked に更新した後、何も起こらない理由を教えていただけませんか? 私がやりたいことは、配列の 0 2 の画像を別の画像に変更することです。何も起こりません。事前にご協力いただきありがとうございます。
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.*;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.*;
public class Board extends JPanel implements MouseListener {
private static boolean[] keyboardState = new boolean[525];
private static boolean[] mouseState = new boolean[3];
private static Image[][] images;
Image house;
int w = 0;
int h = 0;
int xPos;
int yPos;
ImageIcon ii = new ImageIcon(this.getClass().getResource("house.gif"));
ImageIcon iii = new ImageIcon(this.getClass().getResource("house1.gif"));
public Board() {
house = ii.getImage();
h = house.getHeight(null);
w = house.getWidth(null);
images = new Image[10][10];
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
images[i][j] = house;
}
}
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
g2d.drawImage(images[i][j],w*i,h*j,null);
}
}
//g2d.drawImage(house,15,15,null);
}
public void checkMouse()
{
if(mouseState[0])
{
images[0][2] = iii.getImage();
repaint();
super.repaint();
}
}
@Override
public void mousePressed(MouseEvent e)
{
mouseKeyStatus(e, true);
checkMouse();
}
@Override
public void mouseReleased(MouseEvent e)
{
mouseKeyStatus(e, false);
repaint();
}
public static boolean mouseButtonState(int button)
{
return mouseState[button - 1];
}
private void mouseKeyStatus(MouseEvent e, boolean status)
{
if(e.getButton() == MouseEvent.BUTTON1)
mouseState[0] = status;
else if(e.getButton() == MouseEvent.BUTTON2)
mouseState[1] = status;
else if(e.getButton() == MouseEvent.BUTTON3)
mouseState[2] = status;
}