这个问题很明显,我相信它很容易解决,我想知道为什么还没有发布简单易懂的答案。我找到了解释如何创建 *new 事件、更改事件方向、-bubble 等的答案。但是,我还没有找到关于捕获信号然后将其反弹到用户类的 Q/A,然后到一个类,该类是该用户类的用户,依此类推。话虽如此,这是我的问题。
我的班级,ClassOne
,接收按钮的信号,然后必须将该信号传递给ClassTwo
,然后将信号传递给ClassThree
,我怎么在JavaFx中做到这一点。
请注意,该类不得触发新事件,但必须触发已捕获的同一事件。
下面是对我正在尝试做的事情的语法解释。
任何帮助,我的意思是任何输入将不胜感激。
public class MyBoxedButton extends HBox {
private Button btn;
MyBoxedButton(){
// Initialization of all the objects
btn = new Button();
//catch the event emitted by the button
btn.setOnAction((ActionEvent e) ->{
// fire/emit the same received event
?????
});
}
}
/*
This class catches the event emitted by MyBoxedButton and then passes it to ClassThree,
but this does not work, how then can I catch the event and then re-emit it.
*/
class ClassTwo(){
private MyBoxedButton mbb;
public ClassTwo(){
mbb = new MyBoxedButton();
//catch the event emitted by MyBoxedButton
????
// re-emit the caught event
????
}
}
/*
This class catches the event emitted by ClassTwo.
The exersice is ment to show how the messages flow
form one object to a next and then to a next, so on and so forth.
*/
class ClassThree(){
private ClassTwo c2;
public ClassThree(){
c2 = new ClassTwo();
//catch the event emitted by MyBoxedButton
????
// re-emit the caught event
????
}