【发布时间】:2016-08-02 03:42:41
【问题描述】:
我现在正在使用一个程序,该程序向/从服务器发送/接收消息。
我在 ClassOne 中保护了名为 onNotice 的 void,它在服务器发出“通知”(又名消息)时从服务器获取参数:
onNotice(sourceNick, notice){}
我在 ClassTwo 中有一个方法触发 onNotice 的服务器响应:
noticeCheck(sender){
sendNotice("receiver", "sendNotice triggers server response" + sender);
}
//followed by next action
nextAction(){
if(noticeTrue){
doSomething;
return;
}
doSomethingElse;
}
如何在 ClassOne 中为 nextAction 创建 noticeTrue? nextAction 不应该等待 onNotice 收到服务器响应,然后再决定 noticeTrue 是真还是假吗?
非常感谢您的帮助
【问题讨论】:
-
我在类的顶部添加了一个静态布尔值,将 noticeTrue 设置为 false。然后在 onNoticed 完成时将 noticeTrue 更改为 true。谢谢@Matteo!
标签: java sockets if-statement io boolean