java for 等待_如何让程序等待Java中的按钮按下(How to have program wait for a button press in Java)...

博客讨论了如何在Java Swing GUI应用中创建一个简单的模拟程序,该程序在每轮模拟结束后,允许用户通过启用的按钮进行交互。问题在于如何在用户按下“继续”按钮前使程序暂停。博主分享了一段简化代码,其中模拟逻辑在单独的类中,而按钮在视图类中。他们寻求指导如何在用户按下“继续”按钮后才继续执行while循环。
摘要由CSDN通过智能技术生成

Now, I'm not sure if this is possible or even the best way to accomplish what I'm trying to do, but basically I'm creating a very simple simulation program with a very simple Swing GUI.

After each round of the simulation, some buttons on the interface are enabled for the user to make changes and then the user can press the "continue" button to start the simulation again. The simulation itself is basically a while loop that needs to wait for the user action before continuing. My question is how can I have the program stop and wait until the user presses the "continue" button? Please let me know if there are any more details I can provide if this is unclear!

Edit:

I'm going to add some simplified code here so maybe this will make more sense. The program is in two parts, the simulation class and the view. So the button to be pressed is in the view class while the simulation is happening in its class.

Simulation class:

SimulationView view = new SimulationView(); // extends JFrame

while (!some_condition) {

// code

// need user action via button press here before continuing!

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值