从单击JButton时触发的操作中检索值

时间:2014-04-26 18:43:13

标签: java asynchronous jframe action return-value

我在jFrame中有一个jButton链接到一个扩展AbstractAction

的类
//Code from myMainFrame.java
CustomAbstractAction abstractAction1 = new CustomAbstractAction();
JButton jButton1 = new JButton();
...
jButton1.setAction(abstractAction1);

此抽象操作调用自定义jDialog并从中检索对象:

//Code from CustomAbstractAction.java
private Object myObject = null;

@Override
public void actionPerformed(ActionEvent e) 
{
    CustomDialog dial = new CustomDialog ();
    myObject = dial.showDialog();
}

public Object getMyObject()
{
    return myObject;
}

到目前为止,一切正常,我在“myObject”中检索了正确的值,并且我可以使用getter方法获取此值。

问题是要知道何时在myMainFrame中调用它:myMainFrame是否有一种方法可以在我的CustomAbstractAction完成actionPerformed时触发函数? 像

这样的东西
//This doesn't work, but should illustrate what I'm trying to do
abstractAction1.onActionPerformed(function {/*Do stuff*/});

0 个答案:

没有答案