0
我知道这已被问了好几次,但没有任何解决方案为我们工作。 我们正在重新创建具有世界地图的游戏,并且应该在每个国家/地区显示标志。我们通过使用图形方法得到它的工作(有点),但这不是持久的,也不能用var名称来标记一个标志。Java/Swing层标签顶部如果彼此
这就是为什么我们想要在JLabel
中的每一个标志,并在gamePane
内绘制它们,但在他们的指定坐标。所以我们需要能够用z轴进行定位。
GamePane有一个JLabel
与ImageIcon
里面,应该形成背景。最重要的是我们要创建的标志
一些代码(可能没有帮助): -
gamePane = new JPanel();
[...]
public void paintFlagLabel() {
for (Country currentCountry : risiko.getCountryList()) {
JLabel flag = new JLabel();
int x = currentCountry.getX();
int y = currentCountry.getY();
if (currentCountry.getOwningPlayer().equals(this.player)) {
flag.setIcon(new ImageIcon(greenFlag));
} else {
flag.setIcon(new ImageIcon(redFlag));
}
String coordinates = "pos " + x + " " + y;
gamePane.add(flag, coordinates);
gamePane.revalidate();
gamePane.repaint();
}
}