在Java中创建具有相同变量的对象的多个实例
我有一个非模式对话框,我需要显示它同时显示的多个实例。 我将对话框保留为我新建并显示对话框的类中的成员变量。这里有多个可见的对话框实例,但我将其分配给同一个成员变量。(我需要将其作为成员变量进行某些处理)。它工作正常,但我不明白为什么这样工作。我错过了一些非常明显的事情吗?
public class ABC {
CMyDialog m_dlg;
onSomeEvent() {
m_dlg = new CMyDialog();
}
}
onSomeEvent
被多次调用并显示多个对话框。知道 Java 如何管理这些事情吗?我是否需要保留 CMyDialog 数组作为成员变量,而不仅仅是一个类?
非常感谢任何帮助。
提前致谢。 尼廷·K.
I have a modeless dialog which i need to show multiple instances of it displayed at the same time.
I have kept the dialog as a member variable in a class which i new and show the dialog. Here there are multiple instances of dialog visible but i am assigning it to the same member variable.(I need to have it as member variable for some processing). It is working fine but i dont understand why this is working. Am i missig something very obvious?
public class ABC {
CMyDialog m_dlg;
onSomeEvent() {
m_dlg = new CMyDialog();
}
}
onSomeEvent
is called multiple times and multiple dialogs are shown. Any idea how Java manages these things? Do i need to keep an array of CMyDialog as member variable instead of just a single class?
Any help is highly appreciated.
Thanks in advance.
Nitin K.
默认关闭操作 对于
JDialog
来说是HIDE_ON_CLOSE
。如果您不需要多个对话框,您可以只创建一个对话框并使其在onSomeEvent()
中可见。此示例使用切换按钮的itemStateChanged()
处理程序。The default close operation for
JDialog
isHIDE_ON_CLOSE
. If you don't want multiple dialogs, you can create just one and make it visibleonSomeEvent()
. This example uses a toggle button'sitemStateChanged()
handler.