Java 等待返回,直到按下按钮
我正在开发我的第一个大型多文件Java程序。当程序启动时,我的主文件调用另一个创建GUI的文件,填充它并接受信息。然后它应该返回一个Java 等待返回,直到按下按钮,java,user-interface,jframe,jpanel,Java,User Interface,Jframe,Jpanel,我正在开发我的第一个大型多文件Java程序。当程序启动时,我的主文件调用另一个创建GUI的文件,填充它并接受信息。然后它应该返回一个ArrayList,我的主文件应该使用它 问题是我的GUI方法会立即返回一个空的ArrayList,而不是等到按下按钮后再返回 这就是我的ActionListeners当前的工作方式 close.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){
ArrayList
,我的主文件应该使用它
问题是我的GUI方法会立即返回一个空的ArrayList
,而不是等到按下按钮后再返回
这就是我的ActionListener
s当前的工作方式
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是我希望在末尾返回的ArrayList
这是我的主文件中的内容:
JFrame launch = new LaunchWindow();
ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();
rounds = temp.get(0);
temp.remove(0);
order = temp;
connect();
JFrame launch = new LaunchWindow();
ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();
JFrame launch=newlaunchwindow();
ArrayList temp=((启动窗口)启动).createGUI();
轮数=温度获取(0);
移除温度(0);
订单=温度;
connect();
我不希望它运行
rounds=temp.get(0)代码>直到填充ArrayList
之后。我怎样才能等到按下按钮时再做呢?我最后把@Madhan的答案和我自己的答案混在一起了(我想)
我在主文件中调用GUI文件:
JFrame launch = new LaunchWindow();
ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();
rounds = temp.get(0);
temp.remove(0);
order = temp;
connect();
JFrame launch = new LaunchWindow();
ArrayList<Integer> temp = ((LaunchWindow) launch).createGUI();
JFrame launch=newlaunchwindow();
ArrayList temp=((启动窗口)启动).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);
}
});
start.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件e){
temp=pullInfo(txtOrder,txtRounds);
整数轮=温度获取(0);
移除温度(0);
ArrayList顺序=温度;
连接(订单、轮次);
}
});
GUI命令通常是异步的。@Powerlord很棒。但这并不是很有帮助。你是说没有一种方法可以轻松完成我想做的事情吗?将代码放入“开始”按钮的动作中这看起来像一个类似的问题。上面的回答回答了你的问题吗?这些rounds=temp.get(0);移除温度(0);订单=温度;connect()代码>