我想先choose.setVisible(true)
之后
能够选择并在按下确定按钮后
继续执行。
以下代码显示了chooser
和continues
没有等待。
static class box extends JFrame {
Checkbox cboxtps = new Checkbox("Grf1", false);
Checkbox cboxrspt = new Checkbox("Grf2", false);
JLabel lblQts = new JLabel("Please select graphs");
JButton btn1 = new JButton("Go");
public box(String str) {
super(str);
setLayout(new GridLayout(4, 1));
add(lblQts);
add(cboxtps);
add(cboxrspt);
add(btn1);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
System.out.println("You clicked the button");
}
});
}
}
public static void main(String args[]) {
box choose = new box("Select Graphs");
choose.setSize(300, 150);
choose.pack();
choose.setVisible(true);
List<File> filepaths = fileselect();
list = Splitter(filepaths);
}
答案 0 :(得分:0)
由于您在这里异步工作,您必须将choose.setVisible(true)
之后的代码放入actionPerformed回调中,如下所示:
public void actionPerformed(ActionEvent e)
{
System.out.println("You clicked the button");
List<File> filepaths = fileselect();
list = Splitter(filepaths);
}
通常,在处理大量回调时,最好定义辅助函数以避免深度嵌套。