关于button事件执行多个方法,依次将结果返回的问题

syj247 syj247 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在gui中有一个按钮,有三个方法 methodA(),methondB(),methondC()返回值都是String

需求是点击button1后,执行methondA(),并将methodA()的返回值作为button1的Text;继续执行methodB(),更新button1的Text,再执行methodC,更新button1的Text

我的代码如下


@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {

jt.setText(method1());
jt.setText(method2());
jt.setText(method3());
}
}

private string methodA(){
//todo something
System.out.println("方法1被执行");
return "方法一被执行";
}
private string methodB(){
//todo something
System.out.println("方法2被执行");
return "方法二被执行";
}
private string methodC(){
//todo something
System.out.println("方法3被执行");
return "方法三被执行";
}

效果是methondA(),methodB(),methodC(),依次被执行,但是methodA,methodB的返回值未成功的设置为button的Text.
说明:methodA(),methodB()方法中处理的事务非常多。不存在运行太快肉眼无法发现。

...全文
评论 2
收藏 已收藏
分享
返回顶部
syj247
Java SE 62,620 成员 307,251 内容