我在我的程序中创建了一个通用对话框的静态实例
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 事件。我觉得这个问题很愚蠢,抱歉并提前感谢。