[英]Java X Y coordinates
Hi I have been working on a Monopoly project for a couple of days now in order to improve my coding in Java. 嗨,我现在已经在Monopoly项目上工作了几天,以便改进我在Java中的编码。
Most of the board was done using the paint method and I had a hard time calculating where to position each square.I know it's not probably a good ideea to create a board this way I have been told by a friend but this is my first big project in Java and as a programmer and I wana see what comes out of been from my own ideeas. 大部分板子都是用油漆法完成的,我很难计算每个正方形的位置。我知道用这样的方式创建板子可能不是一个好主意,但这是我的第一个重要任务在Java和作为程序员的项目,我看到了来自我自己的ideeas的东西。
My next order of busines would be to set the positions of each piece while the players travers it and I am in need of xy coordinates again.I should also mention I am using the SWING library for the GUI. 我的下一个业务目标是在玩家移动时设置每块棋子的位置,并且我再次需要xy坐标。我还要提到的是我在GUI中使用SWING库。
What I want to know if there is a way to get the xy cordinates of the interface while moving 我想知道是否有一种方法可以在移动时获取界面的xy坐标
Here's an example with two different types of coordinates you might mean: 以下是您可能意味着两种不同类型坐标的示例:
JPanel panel = new JPanel();
/*
* Get X coordinate of panel's origin relative to the parent's
* upper left corner measured in pixels.
*/
panel.getX();
/*
* Get coordinates of mouse click relative to the source component.
*/
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
Point p = event.getPoint();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.