问题描述
问题简介: 我正在研究与JFrame相关的Aplication。在某些时候,我必须:
-
标签的
- 更改图标
- 停止过程
- 等待
- 恢复过程
问题从一开始就出现。如果我暂停应用-JLabel图标将不会更改。 目前,我尝试了几种暂停方法,包括: Thread.sleep(), this.wait()和带有 synchronize 的变体。我还尝试将 .updateUI()放置在每个适当的位置,而不是放置位置。问题本身对我毫无意义。
这是我的主要空白代码段:
private void checkCard(java.awt.event.MouseEvent evt,int y,int x){
if(this.memory.getGrid()[y][x]>0){
clicks++;
this.specialIcon(y,x);
switch (clicks) {
case 1:
pos1[0]=y;
pos1[1]=x;
break;
case 2:
this.labelCards[pos2[0]][pos2[1]].updateUI();
this.grid.updateUI();
this.core.updateUI();
pos2[0]=y;
pos2[1]=x;
this.memory.play(pos1,pos2);
//CHECK POS1
//CHECK POS2
if(!memory.getSolved(pos2)){
generateThreadWait();
this.labelCards[pos2[0]][pos2[1]].setIcon(new ImageIcon(this.src+"unkNown.png"));
this.labelCards[pos1[0]][pos1[1]].setIcon(new ImageIcon(this.src+"unkNown.png"));
} else if(memory.getSolved(pos2)){
this.labelCards[pos2[0]][pos2[1]].setIcon(new javax.swing.ImageIcon(this.src+"solved.png"));
this.labelCards[pos2[0]][pos2[1]].addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
//DEBUG
//System.out.println("disABLED");
}
});
this.labelCards[pos1[0]][pos1[1]].setIcon(new javax.swing.ImageIcon(this.src+"solved.png"));
this.labelCards[pos1[0]][pos1[1]].addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
//DEBUG
//System.out.println("disABLED");
}
});
};
this.clicks =0;
break;
default:
break;
}
}
}
和“ generateThreadWait()” 无效:
private synchronized void generateThreadWait() {
final java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
try {
System.out.println("Inside synchronized block entry..." + dtf.format(java.time.LocalDateTime.Now()));
this.wait(2000);
System.out.println("Inside synchronized block exit..." + dtf.format(java.time.LocalDateTime.Now()));
} catch (InterruptedException e) {
e.printstacktrace();
}
任何想法我都会很高兴。谢谢!!!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)