在Java中创建具有相同变量的对象的多个实例 [英] Creating multiple instance of an object with same variable in Java

查看:152
本文介绍了在Java中创建具有相同变量的对象的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无模式对话框,我需要显示同时显示的多个实例. 我将对话框保留为新类并显示对话框的类中的成员变量.这里有对话框的多个实例可见,但我将其分配给相同的成员变量.(我需要将其作为成员变量进行某些处理).它工作正常,但我不明白为什么这样工作.我错过了一些很明显的东西吗?

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被多次调用,并显示多个对话框.知道Java如何管理这些东西吗?我是否需要将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.

先谢谢了. 尼丁·K.

Thanks in advance. Nitin K.

推荐答案

尽管有几个可见的对话框实例,但每个实例在主内存中都占据一个单独的空间.变量名称可以相同,但是所有对话框实例不共享相同的内存.我希望这就是您要的.

Although there are several instances of dialog visible, each of it occupies a separate space in main memory. The variable name may be same, but all the dialog instances do not share same memory. I hope this is what you had asked for.

这篇关于在Java中创建具有相同变量的对象的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆