删除带有“相同”的 JLabels姓名
我正在做一个四连胜的游戏,我将红色或绿色的棋子作为标签添加到面板游戏中,但始终是相同的标签。我的代码是这样的(相关的)
labeljogo = new JLabel(new ImageIcon( bola ));
if(f.getSource()==setaL1 && c1==6 && modoDeJogo==2 || setaPc=="setaL1" && c1==6 && modoDeJogo==3 && jogadorActual==2 || f.getSource()==setaL1 && c1==6 && modoDeJogo==3 && jogadorActual==1 || modoDeJogo==4 && setaPc=="setaL1" && c1==6)
{
labeljogo.setBounds(150, 100, 60, 60);
c1++;
matrix[1][0]=jogadorActual;
}
if(f.getSource()==setaL1 && c1==6 && modoDeJogo==2 || setaPc=="setaL1" && c1==6 && modoDeJogo==3 && jogadorActual==2 || f.getSource()==setaL1 && c1==6 && modoDeJogo==3 && jogadorActual==1 || modoDeJogo==4 && setaPc=="setaL1" && c1==6)
{
labeljogo.setBounds(150, 100, 60, 60);
c1++;
matrix[1][0]=jogadorActual;
}
(...),它一直持续到所有 8*8 块都在面板中,
图像 bola 通过更改播放器而更改。
我怀疑是否有任何方法可以清理所有具有相同名称的 JLabel。因为当我调用它时,
panel.remove(labeljogo);
它只会删除最后一个。
有没有办法删除这个 JLabel 而不影响其他 JLabel?
I'm doing a 4 in a row game, and i'm adding the red or green piece as a label, but always the same label, to the panel game. My code is like this (the relevant one)
labeljogo = new JLabel(new ImageIcon( bola ));
if(f.getSource()==setaL1 && c1==6 && modoDeJogo==2 || setaPc=="setaL1" && c1==6 && modoDeJogo==3 && jogadorActual==2 || f.getSource()==setaL1 && c1==6 && modoDeJogo==3 && jogadorActual==1 || modoDeJogo==4 && setaPc=="setaL1" && c1==6)
{
labeljogo.setBounds(150, 100, 60, 60);
c1++;
matrix[1][0]=jogadorActual;
}
if(f.getSource()==setaL1 && c1==6 && modoDeJogo==2 || setaPc=="setaL1" && c1==6 && modoDeJogo==3 && jogadorActual==2 || f.getSource()==setaL1 && c1==6 && modoDeJogo==3 && jogadorActual==1 || modoDeJogo==4 && setaPc=="setaL1" && c1==6)
{
labeljogo.setBounds(150, 100, 60, 60);
c1++;
matrix[1][0]=jogadorActual;
}
(...) and it continues until all the 8*8 pieces are in the panel
the image bola changes by changing player.
My doubt is if there is any way of cleaning all this JLabels that all have the same name. Because when I call the
panel.remove(labeljogo);
It only removes the last one.
Is there any way of removing this JLabels without affecting the other JLabels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此方法按高度删除
JLabel
。效果很好。used this method to remove the
JLabel
s by height. It worked fine.