【发布时间】:2017-12-27 17:44:55
【问题描述】:
我知道这个问题已经被问过好几次了,但没有一个解决方案对我们有用。 我们正在重新创建一个游戏,它有一张世界地图,并且应该在每个国家都显示国旗。我们通过使用图形方法让它工作(有点),但这不是持久的,我们也不能通过 var 名称来处理标志。
这就是为什么我们希望在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();
}
}
【问题讨论】:
标签: java swing jframe jpanel z-axis