2012-06-06 22 views
0

我已經在我的計劃通用對話框中單擊OK,不會觸發

static GenericDialog SaveDialog = null; 

創建了一個通用對話框的靜態實例,下面是顯示對話框

public boolean DispSaveDialog() 
{ 
    //gd.addStringField("Identity : ", "annot"); 
    if(SaveDialog == null) 
    { 
     SaveDialog = new GenericDialog("Save"); 
     Panel idnPanel = new Panel(); 
     idnPanel.add(new Label("Identity")); 
     idnTextComp = new TextField("annot"); 
     csPrefix = idnTextComp.getText(); 
     TextListener tl = new TextListener() { 

      @Override 
      public void textValueChanged(TextEvent e) { 
       // TODO Auto-generated method stub 
       csPrefix = idnTextComp.getText(); 
      } 
     }; 
     idnTextComp.addTextListener(tl); 
     idnPanel.add(idnTextComp); 
     SaveDialog.addPanel(idnPanel); 
     final TextComponent textComponent = new TextField(); 
     ActionListener al = new ActionListener() { 

      @Override 
      public void actionPerformed(ActionEvent e) { 
       // TODO Auto-generated method stub 
       String label = e.getActionCommand();     
       //csPrefix = gd.getNextString(); 
       if (label=="Browse") 
       {     
        String csFilename = imp.getTitle();     
        csTextFileName = FileNameProcess(csFilename);  
       } 
       textComponent.setText(csTextFileName); 
      } 
     }; 
     Button btBrowse = new Button("Browse"); 
     btBrowse.addActionListener(al);  
     Panel panel = new Panel(); 

     panel.add(new Label("Folder : ")); 
     //textComponent.setBounds(gd.getBounds()); 
     panel.add(textComponent); 
     panel.add(btBrowse); 
     SaveDialog.addPanel(panel);   
    } 
    SaveDialog.showDialog(); 
    return true; 
} 

的問題,我的代碼,第二次我面對的是,當我第二次打開對話框時,OK和Cancel事件不會被觸發。 我有一種感覺,這個問題是愚蠢的,抱歉,並提前感謝。

+0

問題是,最有可能的監聽器仍然被鏈接到GenericDialog的第一個實例,而不是與新的實例。你有沒有嘗試調試程序,以檢查第二次綁定到監聽器的對象大約 –

+0

這是一個爲imageJ開發的插件,所以我不能調試相同的。我試圖顯示字符串,但我似乎無法理解的行爲 – Preethi

+0

你試過,如果問題保持不變,你從你的變量中刪除靜態部分? – Thihara

回答

0

上面的代碼是這樣的,當通用對話框第二次顯示舊值將被保留.. 我做了一個解決方法,以保存第一次進入靜態字符串變量和負載他們檢查空值後。

這不是解決方案,只是一種解決方法,所以我可以按時關閉問題。 :(

相關問題