java label的覆盖问题

花不如酒 2014-10-19 07:26:45
public chess(){
super();
this.setResizable(false);
this.getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("中国象棋");
JLabel label = new JLabel();
label.setLayout(null);
ImageIcon background = new ImageIcon(this.getClass().getResource("/Image/qipan.jpg"));
label.setBounds(200, 0, background.getIconWidth(), background.getIconHeight());
this.setBounds(100, 100, background.getIconWidth(), background.getIconHeight()+27);
this.getContentPane().add(label);
chessman game = new chessman(this);
game.start();
this.setVisible(true);
label.setIcon(background);
}//这个是棋盘
public void start(){
int num;
JLabel qizi = null;
for(int i=0;i<chessFlag.length;i++){
for(int j=0;j<chessFlag[i].length;j++){
num = chessFlag[i][j];
if(num == 0) continue;
ImageIcon image =new ImageIcon(this.getClass().getResource("/Image/"+num+".gif"));
qizi = new JLabel();
qizi.setSize(image.getIconWidth(), image.getIconHeight());
qizi.setIcon(image);
qizi.setLocation(j*60, i*60);
qizis.add(qizi);
c.getContentPane().add(qizi);
}
}

}

为什么棋盘会把棋子覆盖了,小白求大神知道,谢谢
...全文
202 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
花不如酒 2014-10-25
  • 打赏
  • 举报
回复
我发现问题了,在new cheaaman game的时候把JLabel传进去,再在JLabel上添加棋子就好了
猿哥 2014-10-19
  • 打赏
  • 举报
回复
设置一下棋盘和棋子距离屏幕的距离,把棋子设置到离屏幕比棋盘到屏幕的距离更近一点
花不如酒 2014-10-19
  • 打赏
  • 举报
回复
label.setIcon(background); 棋盘的最后一句,我专门放在后头的,放在了中间也是一样,棋盘把棋子覆盖了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧