【发布时间】:2014-01-29 12:33:03
【问题描述】:
我有这个功能,我想在点击按钮时返回一个值。我知道它不起作用,但我该如何解决这个问题?我已经用谷歌搜索过,但找不到相关的东西。
我的代码:
public String OutputText()
{
layout.show(mainpanel, "PANEL");
testbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
return textfield.getText();
}
});
}
【问题讨论】:
-
为什么要函数返回值?
-
你想用'returned'值做什么?
-
所以这将起作用:'system.out.println(OutputText());例如:)
-
为什么不直接在监听器内部做呢?
标签: java swing button return textfield