我正在写一个基于回合的互联网游戏。我尝试弹出一个应该在前面的窗口,直到输入流准备就绪。我创造了这样的行为,但它似乎不起作用。使用SwingUtilities.invokeLater弹出窗口
class CustomBlockerDialog extends JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
public CustomBlockerDialog(Frame owner, String text) {
super(owner, true);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setSize(300, 100); // Adjust if needed
setTitle("");
add(new JLabel(text, SwingConstants.CENTER));
}
}
final CustomBlockerDialog block = new CustomBlockerDialog(null, "Not your turn");
SwingUtilities.invokeLater(new Runnable() {//A
@Override
public void run() {
System.out.println("show");
block.setVisible(true);
}
});
boolean one_write_only = true;
while(in.ready()){ /* C*/
if(one_write_only){
System.out.println("waiting server");
one_write_only = false;
}
};
System.out.println("suppose to hide");
SwingUtilities.invokeLater(new Runnable() {//B
@Override
public void run() {
System.out.println("hide");
block.setVisible(false);
}
});
看起来“A”和“B”在“C”之后执行,我不知道为什么。
............你好??? –
对不起,很久没有发帖了。我记得它,但我有很多工作。 – slawic