1)ConnectionRequest作爲參數連接和Toastbar不顯示使用的ActionListener問題
ArrayList<Map<String, Object>> responses;
public void groupConnection(StateMachine sm, ActionListener al) {
ConnectionRequest connectionRequest = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
responses = (ArrayList<Map<String, Object>>) parsedData.get("root");
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
al.actionPerformed(null);
}
});
}
@Override
protected void handleException(Exception err) {
//System.out.println("handleException " + err);
}
@Override
protected void handleIOException(IOException err) {
//toastbar doesnt work here but dialogBox works, if showForm("Groups") is used, toastbar is also shown along with dialogbox
//ToastBar.showErrorMessage("Please check your network connection", 4000);
//sm.showForm("Groups", null);
Dialog.show("", "Please check your network connection", "ok", null);
}
};
AllUrl allUrl = new AllUrl();
connectionRequest.setUrl(allUrl.groupsMenu);
InfiniteProgress ip = new InfiniteProgress();
Dialog d = ip.showInifiniteBlocking();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
在connectionRequest代碼以上,如果沒有網絡連接,它給IOException異常:可達時,由下面的handleIOException方法,但如果我處理在那裏使用dialogBox,它的工作原理。相反,Toastbar不起作用,爲什麼呢?如果我使用showForm(「Form」,null)以及dialogBox和toastbar,則會重複調用相同的表單,並且在出現多次對話框時也會看到Toastbar。
2)postForm(形式F)的方法
connectionGroup = new GroupConnection();
connectionGroup.groupConnection(StateMachine.this, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
//checking connectionGroup.responses == null doesnt work since the connectionRequest gives IOException if no network.So Toastbar doesnt work here.
if (connectionGroup.responses == null) {
ToastBar.showErrorMessage("Please check your network connection", 4000);
}
if (connectionGroup.responses != null) {
for (Map<String, Object> element : connectionGroup.responses) {
String tableName = (String) element.get("name");
TextArea nameLabel = new TextArea(tableName.toUpperCase());
f.add(singleRowContainerr);
}
}
}
}
在上述postForm方法中,我使用的,以檢查是否有網絡連接或不通過檢查:如果(connectionGroup.responses == NULL){做不服...},它不起作用,因爲connectionRequest給IoException &不運行connectionRequest內的代碼。
如何解決這個問題?我必須在toastBar中顯示「檢查連接」,並在文本「無連接」中顯示標籤。 PS我需要將我的所有組件& connectionRequest放在postForm中,因爲我需要在調用connectionRequest之前轉到表單。