【发布时间】:2015-04-09 22:46:44
【问题描述】:
我试图将棋盘的 x 和 y 坐标指向特定的数组值。例如,x:145 y:347 应该指向我棋盘上的 [3,1]。棋盘的大小是 460 x 460,但我不知道如何计算。数组是8×8,和棋盘一样。
代码:
public Container c;
c = getContentPane();
setBounds(100,75,460,460);
public JPanel pnlMain = new JPanel(new GridLayout(2, 1));
pnlMain.setBounds(2, 2, 460, 860);
c.add(pnlMain);
public void MousePressed(MouseEvent e){
if(e.getX() < 460 && e.getY() < 460){
int x = e.getX() / 57;
int y = e.getY() / 175;
}
}
调试时我没有得到正确的数组位置。
【问题讨论】:
-
你的意思是
e.getY() / 175? -
@Alejandro 是的对不起
标签: java arrays jpanel mouseevent containers