我需要访问定义它们的类之外的 gui 组件。我的 gui 类包含以下用于在其上放置对象的代码:
/**
* Create contents of the window.
*/
protected void createContents() {
shlCertificatesmanager = new Shell(Display.getDefault());
shlCertificatesmanager.setSize(450, 300);
shlCertificatesmanager.setText("CertificatesManager");
shlCertificatesmanager.setLayout(new RowLayout(SWT.HORIZONTAL));
MenuItemListener menuListener = new MenuItemListener(shlCertificatesmanager);
Menu menu = new Menu(shlCertificatesmanager, SWT.BAR);
shlCertificatesmanager.setMenuBar(menu);
MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE);
mntmNewSubmenu.setText("File");
Menu menu_1 = new Menu(mntmNewSubmenu);
mntmNewSubmenu.setMenu(menu_1);
MenuItem mntmOpenCertificate = new MenuItem(menu_1, SWT.NONE);
mntmOpenCertificate.setText("Open Certificate");
mntmOpenCertificate.addSelectionListener(menuListener);
MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
mntmExit.addSelectionListener(menuListener);
mntmExit.setText("Exit");
MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
mntmHelp.setText("Help");
Menu menu_2 = new Menu(mntmHelp);
mntmHelp.setMenu(menu_2);
MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
mntmAbout.setText("About");
mntmAbout.addSelectionListener(menuListener);
Label lblAliasName = new Label(shlCertificatesmanager, SWT.NONE);
lblAliasName.setText("Alias name: ");
Label label = new Label(shlCertificatesmanager, SWT.NONE);
label.setText("___________");
}
现在我需要从外部类访问其中一些组件,在这种情况下,我需要从 MenuItemListener 类访问两个标签(lblAliasName,标签)。
有办法访问它们吗?(也许像 Android 的 findViewById 方法或类似方法?)
或者我需要例如让它们以某种方式从其他类访问?(创建一个将被 MenuItemListener 类和 GuiWindow 类使用的 gui 组件的类)