等待 return 直到按下按钮

Wait to return until button is pushed

我正在开发我的第一个大型多文件 Java 程序。当程序启动时,我的主文件调用另一个创建 GUI 的文件,填充它并接受信息。然后它应该 return 一个 ArrayList,我的主文件应该使用它。

问题是我的 GUI 方法立即 return 使用空 ArrayList,而不是等到按下按钮之后。

目前我的 ActionListener 就是这样工作的

close.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
    System.exit(0);
  }
});

start.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
    temp = pullInfo(txtOrder, txtRounds);
  }
});

其中 temp 是我想要 return 最后的 ArrayList

这是我的主文件中的内容:

 JFrame launch = new LaunchWindow(); 
 ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();
 rounds = temp.get(0);
 temp.remove(0);
 order = temp;
 connect();

我不希望它 运行 rounds = temp.get(0); 直到 ArrayList 被填充。我怎样才能让它等到按下按钮?

我最终将@Madhan 的答案与我自己的答案混为一谈(我认为)

我在主文件中调用GUI文件:

JFrame launch = new LaunchWindow(); 
ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();

然后更改了我的 start.addActionListener 方法,从那里调用下一个方法。

start.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
    temp = pullInfo(txtOrder, txtRounds);
    int rounds = temp.get(0);
    temp.remove(0);
    ArrayList<Integer> order = temp;
    connect(order, rounds);
  }
});