java label的覆盖有关问题
java label的覆盖问题
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);
}
}
}
为什么棋盘会把棋子覆盖了,小白求大神知道,谢谢
------解决思路----------------------
设置一下棋盘和棋子距离屏幕的距离,把棋子设置到离屏幕比棋盘到屏幕的距离更近一点
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);
}
}
}
为什么棋盘会把棋子覆盖了,小白求大神知道,谢谢
------解决思路----------------------
设置一下棋盘和棋子距离屏幕的距离,把棋子设置到离屏幕比棋盘到屏幕的距离更近一点