我正在根据我的 JPanel (640x480) 的宽度/高度进行一些计算和绘图,但是当我输出鼠标的实际位置时,我注意到它的实际边界为 (622x441)。为什么会这样,我该如何弥补?
这是我的 GamePanel 构造函数
public GamePanel(){
wallBoard = new WallBoard();
player = new Player(100, 100);
Map<String, GameObject> startingEquipment = new HashMap<String, GameObject>();
startingEquipment.put("Sword and Sheild", new Sword(player.getX(), player.getY()));
player.equip(startingEquipment);
enemy = new Enemy(10, 10);
objects.add(player);
objects.add(enemy);
mouseSelection = new MouseSelection();
setSize(new Dimension(640, 480));
setDoubleBuffered(true);
setFocusable(true);
addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);
frame = new GameFrame();
frame.pack(); //this makes the window just the bar at the top
//frame.setUndecorated(true); crashes the program
frame.addKeyListener(this);
frame.add(this);
t = new Thread(this);
t.start();
hud = new HeadsUpDisplay(getWidth(), getHeight());
}