在另一个类中使用Listener

时间:2022-06-14 16:12:36

I have a MainInterface and some other Classes. The other Classes are GUI-Elemnts which I add to the MainInterface. In the TreeClass I use a Tree for selecting diffrent things. In this Class i have a TreeListener to react on TreeSelection.

我有一个MainInterface和一些其他类。其他类是我添加到MainInterface的GUI-Elemnts。在TreeClass中,我使用Tree来选择不同的东西。在这个类中,我有一个TreeListener来对TreeSelection作出反应。

My goal is, that when I select something in the Tree, that the MainInterface react based on the Selection. I have to Classes next to the named one (JPanel Red and JPanel Blue). Based on the Selection the two Classes (extends JPanel) have to appear.

我的目标是,当我在树中选择一些内容时,MainInterface会根据Selection做出反应。我必须在命名的一个旁边的类(JPanel Red和JPanel Blue)。基于Selection,必须出现两个类(扩展JPanel)。

I tried this already with Buttons in the MainInterface and it worked. But what i dont know how to do is, that the two Classes switch based on the TreeSelectionListener in the TreeClass ... so my main Problem is, that I dont know how the MainInterface listen to the Tree ...

我已经在MainInterface中使用Buttons尝试了这个并且它有效。但我不知道该怎么做,两个Classes基于TreeClass中的TreeSelectionListener切换...所以我的主要问题是,我不知道MainInterface如何监听树...

1 个解决方案

#1


0  

It sounds like your MainInterface should register itself as a tree selection listener to your tree's model. There's an example at the bottom of the page.

听起来你的MainInterface应该将自己注册为树模型的树选择监听器。页面底部有一个例子。

#1


0  

It sounds like your MainInterface should register itself as a tree selection listener to your tree's model. There's an example at the bottom of the page.

听起来你的MainInterface应该将自己注册为树模型的树选择监听器。页面底部有一个例子。